【发布时间】:2014-05-29 07:43:15
【问题描述】:
当我使用以下代码时,我无法在 ajax 中获取回调响应值
$.ajax({
type: 'POST',
jsonpCallback: 'jsonCallback',
contentType: 'application/json',
url: apiurl,
dataType: "jsonp",
data: jsonstring,
success: function(response)
{
callback(response);
token = response;
},
error: function(jqXHR, textStatus, errorThrown){
alert('Not Permitted ' + textStatus);
}
但是当我改变上面的 dataType: "text" 就可以了。
当我使用 dataType:"jsonp" 时如何获得响应。
我的java响应如下:
return Response.status(200).entity("HAI").build();
非常感谢任何帮助。
【问题讨论】:
-
你在成功部分做
console.log(response)会得到什么? -
如果你想让 dataType:"jsonp" 工作,那么你的响应(来自服务器端页面)必须是 json 编码字符串而不是纯文本!
-
实际上成功部分不起作用。总是调用失败。
标签: java javascript jquery ajax