2

我已经部署了一个 REST Web 服务,并且该服务返回字符串作为响应。当我发送跨域 jQuery ajax 请求时,我得到'parsererror'。

下面是弹簧控制器:

@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
-----^

请尽快提供帮助。

4

1 回答 1

3

终于解决了。

contentType: 'text/plain'从 ajax 方法中删除了 , 它工作正常。

于 2012-08-14T07:25:24.750 回答