Javascript 无法使用$.ajax()获取REST响应
下面是我的方法Javascript 无法使用$.ajax()获取REST响应,javascript,jquery,ajax,rest,Javascript,Jquery,Ajax,Rest,下面是我的方法 function getCurrentUserName() { $.ajax({ type: "GET", url: "http://localhost:8099/rest/prototype/1/space/ds", crossDomain:true, dataType: "jsonp", success: function(resp){ alert("Server said123:\n '" + re
function getCurrentUserName()
{
$.ajax({
type: "GET",
url: "http://localhost:8099/rest/prototype/1/space/ds",
crossDomain:true,
dataType: "jsonp",
success: function(resp){
alert("Server said123:\n '" + resp.name + "'");
},
error:function(e){
alert("Error"+e)
}
});
});
}
我是通过点击按钮来调用它的,我没有看到任何警报,当我在浏览器上键入url时,我会得到xml格式的响应,但我不会在脚本中得到响应。
有人能帮我吗?我是不是遗漏了什么?
谢谢:)看起来像是JSON解析错误 尝试使用
json
而不是jsonp
function getCurrentUserName()
{
$.ajax({
type: "GET",
url: "http://localhost:8099/rest/prototype/1/space/ds",
crossDomain:true,
dataType: "json",
success: function(resp){
alert("Server said123:\n '" + resp.name + "'");
},
error:function(e){
alert("Error"+e)
}
});
});
}
您是否已在开发人员工具中检查请求是否确实发出?将错误功能添加到,并放置laert以检查是否出现错误。是的,请求已发出,并显示在浏览器控制台中。它返回[HTTP/1.1 200 OK 31ms]您能显示处理请求的控制器方法吗?您得到了什么错误?我得到了相同的错误。。rest调用返回的数据是xml格式的。我需要Json格式的。我还在尝试下面的代码“$.ajax({type:'GET',url:”,数据:{},数据类型:“xml”,成功:函数(xml){var clientid=$(xml).find('avatarUrl').first().text();alert(“+clientid);}});”