【发布时间】:2013-12-13 07:02:26
【问题描述】:
我在服务器路径中动态存储一些 JSON 文件并使用 struts 2 框架检索 JSON 数据。当请求 AJAX 调用以检索 JSON 时,我得到的 URL 路径为 www.mydomain.com:8080/mydomain.com/myserver/myjsonpath/jsonfile.json 而不是 http://www.mydomain.com/myserver/myjsonpath/jsonfile.json。我还想提一下,由于这个原因,我无法进入 AJAX 的成功字段。它总是进入错误字段。我是在 Firebug 的帮助下才知道这个 URL 的。
//My AJAX request
String img_path="www.mydomain.com/myserver/";
String json_url=img_path+"/myjsonpath";
$(document).ready(function(){
alert("<%=json_url%>/jsonfile.json"); // here am getting correct URL path from server
$.ajax({
type: "get",
url:"<%=json_url%>/jsonfile.json",
dataType: "json",
success:function(data){
alert(data); // not entering here
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status); // enters here
}});
【问题讨论】:
标签: jquery ajax json jsp struts2