jQuery-mobile:JSONP请求使用$.ajax(),$.getJSON未触发回调函数
我试图从我的web服务器获取JSON数据,但它不起作用jQuery-mobile:JSONP请求使用$.ajax(),$.getJSON未触发回调函数,jquery,ajax,mobile,Jquery,Ajax,Mobile,我试图从我的web服务器获取JSON数据,但它不起作用 $.mobile.showPageLoadingMsg(); //$.getJSON('http://localhost:8000/'+site+'/?format=json&callback=?', {}, function(){alert();}); $.ajax({ url : 'http://localhost:8000/'+site +'/?format=json&callback=?', typ
$.mobile.showPageLoadingMsg();
//$.getJSON('http://localhost:8000/'+site+'/?format=json&callback=?', {}, function(){alert();});
$.ajax({
url : 'http://localhost:8000/'+site +'/?format=json&callback=?',
type : 'GET',
dataType : 'jsonp',
jsonp : 'callback',
success : function(){alert('success');},
error : function(){alert('fail')}
});
$.getJSON
,$.ajax
两个方法的回调函数根本没有启动。
有什么问题吗
我的web服务器的代码:
response_data.append({
'user_nickname' : post.user_nickname,
'title' : post.title,
'recommend' : post.recommend,
'oppose' : post.oppose,
'date' : str(post.date),
'hit' : post.hit,
'commentcount' : post.commentcount
})
return HttpResponse(simplejson.dumps(response_data), mimetype='application/json')
在insector中,它返回get
,200,ok,因此HttpResponse
没有问题
以下是回应:
[{“命中”:5,“标题”:”
\uc624\ud1a0\uc774\uc2a4\ucf00\uc774\ud551\ub418\ub294\uac00“,
“评论计数”:0,“反对”:0,“建议”:0,“日期”:2012-07-24
07:01:22.453000+00:00,“用户昵称”:
“\ud55c\uae00\ub85c\uc5bc\ub9c8\ub098\uae38\uac8c\uae4c\uc9c0\uac00\ub2a5\ud558\ub7ef\uc778\u3131\u3147\u3139\u3147\ub05d”},
{“命中”:4,“标题”:“\uc5ec\uae30\uae00\uc4f0\uba74?”,
“评论计数”:1,“反对”:0,“建议”:0,“日期”:2012-07-24
06:52:05.125000+00:00,“用户昵称”:
“\ud55c\uae00\ub85c\uc5bc\ub9c8\ub098\uae38\uac8c\uae4c\uc9c0\uac00\ub2a5\ud558\ub7ef\uc778\u3131\u3147\u3139\u3147\ub05d”}]
$.ajax()
从不启动成功回调函数。它只调用错误的警报('fail')代码>您的响应不是JSONP:它只是一个JSON数组
如果将ajax
调用中的数据类型更改为'json'
,则应触发回调
但是如果您真的需要使用JSONP——如果您试图进行跨站点通信——那么您需要返回有效的JSONP作为服务器响应。您的服务器需要以javascript函数调用的形式响应字符串,使用jsonp
参数的值作为函数名,JSON响应作为函数参数。是否有javascript函数回调?(如函数回调(){alert('hello');})?