我已经部署了 REST Web 服务,该服务返回字符串作为响应。 当我发送跨域 jQuery ajax 请求时,我收到“parsererror”。
下面是 Spring Controller :
@RequestMapping(value="/TestService",method=RequestMethod.GET)
@ResponseBody
public String testServiceGet()
{
return "This is GET";
}
下面是 jQuery ajax() 方法:
$.ajax({
url: 'http://localhost:8080/Example_REST_WS_Deploy/service/TestService',
dataType: 'jsonp',
crossDomain: true,
contentType: 'text/plain',
success : function(data, textStatus, xhr) {
alert(data);
},
error : function(xhr, textStatus, errorThrown) {
alert("Error ->" + textStatus);
}
});
我们在FF浏览器错误控制台中收到的错误如下:
SyntexError: missing ; before statement
This is GET
-----^
请尽快提供帮助。
最佳答案
终于解决了。
我从 ajax 方法中删除了 contentType: 'text/plain'
,它工作正常。
关于jquery - jQuery 跨域 ajax 请求 Spring Rest Web 服务的 Parsererror,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11946857/