|
貌似有相似问题的帖子,但该帖没给出解决代码,故再发一篇,请知道的朋友帮忙
http://www.justep.com/cn/bbs/forum.php?mod=viewthread&tid=76106&extra=page%3D1&page=1
想用手机端ajax访问另一个网站(asp.net mvc)返回的内容,用json请求会报错。看了上帖感觉是要用jsonp。
服务端返回:Json(lst.ToArray(), JsonRequestBehavior.AllowGet);
手机端面代码:
$.ajax({
"type" : "post",
"async" : false,
"dataType" : "jsonp",
"url" : url,
"jsonp":"callback",
"jsonpCallback":"oncallback",
"data" : {
"personName" : uid,
// 序列化参数JSON字符串
"password" : pwd
},
"success" : function(data, textStatus) {
debugger;
if (data == "Failed") {
alert("用户名或密码错误");
} else if (success) {
success(data);
}
},
"error" : function(XMLHttpRequest, textStatus, errorThrown) {
debugger;
}
});
目前的问题是:服务端能够响应请求并返回,但手机端总是进error,不能进success。提示错误:"oncallback was not called"。
另关于"jsonp":"callback", "jsonpCallback":"oncallback",这部分的代码怎么写也不是很清楚。
感觉帮忙。
|
|