美元.getJSON不工作跨域与我
$.getJSON does not work across domain with me?
以下代码对我不起作用:
$.getJSON(url,
function (data) {
if (data.results[0]) {
alert('hi');
$.each(data["Rows"], function (i, el) {
$("#target").append("<a href='"" + el[1] + "'">" + el[2] + "</a><br />");
})
//container.html(data);
} else {
var errormsg = '<p>Error: could not load the data.</p>';
container.html(errormsg);
}
});
这里是我传递的url: http://www.somedomain.com/page.aspx?sid=6BB5B614-4C43-45DF-BA7D-47A71F0753EF&jsoncallback=?这是返回的JSON
{"Columns":["id","Article_Url","Article_Title","date","num"],
"Rows":[
["5bb93b83-d129-4ca9-8999-ed54910b824d","97.74.67.146/test.html","test","'/Date(1316189236173)'/",25],
["82d62b61-d96b-489a-ae91-008b897db553","97.74.67.146/testx.html?xx=x","test","'/Date(1316256259490)'/",11],
["97aaf346-1146-429e-bc5a-fcfa4b2d934b","97.74.67.146/testx.html","test","'/Date(1316255702510)'/",4],
["2fea1222-e254-4db9-a68e-5129a0d87e8e","97.74.67.146/qn_news_story_s.asp?storyid=1093442005","Oman invests USD3.8b in constructing dry dock","'/Date(1316188504010)'/",2],
["82fe900d-eefe-4540-87a4-1fe6057234a7","http://www.menafn.com/qn_news_story.asp?StoryId={83510500-a24b-4f87-9bf1-3985134ee4b6}","Title 1","'/Date(1315411910897)'/",1],
["217f8e33-8723-4de3-9afc-438d7172f90e","http://www.menafn.com/qn_news_story_s.asp?StoryId=1093437815&src=MOEN","Title 1","'/Date(1315411969900)'/",1]
]
}
我做错了什么?! getJSON就像任何其他受同源策略影响的ajax请求一样,禁止跨域ajax请求。
你可以通过JSONP来解决这个问题。
编辑:
我只是读getJSON应该做一个自动回退到json,如果URL包含一个callback
-参数:
JSONP
如果URL包含字符串"callback=?"(或类似的,由(服务器端API),请求被当作JSONP处理。看到$.ajax()中jsonp数据类型的详细讨论。
因为你有一个jsoncallback
参数这一切可能工作-但你发布的响应不使用这个回调函数(也许是因为你只是给?
作为回调名称),所以这可能是整个问题:张贴一个函数名作为回调,并实现该函数在你的一边。
相关文章:
- 无法让getjson在高库存上工作
- $.getJSON 到一个带有 include_once 的 php 失败了,但它完成了工作
- $.getJSON 和 google fonts API 停止在 Internet Explorer 中工作,jQuer
- jQuery.getJSON无法在具有特殊字符的IE中工作
- 从android webview调用时getJSON不工作
- getJSON 在服务器上不起作用,但在本地工作
- 为什么不't多个$.getJSON调用工作正常
- 美元.getJSON不能与本地JSON文件一起工作
- 我的$. getjson()脚本无法工作
- 美元.getJson不能在IE中工作
- $. getjson()在IE9中工作,但不在Chrome和FireFox中,我的代码有什么问题
- jQuery onPropagation不能与.getjson()一起工作
- ie浏览器的jQuery getJSON不能工作
- 美元.getJSON不能工作
- 美元.getJSON不工作跨域与我
- 美元.getJSON with for循环,仅在调试时工作
- JSONP通过getJson不工作
- getJSON不能在Safari中工作
- 让getJSON与codeigniter一起工作时遇到麻烦
- Getjson查询不工作