jquery - jQuery 跨域 ajax 请求 Spring Rest Web 服务的 Parsererror

标签 jquery spring-mvc cross-domain restful-url

我已经部署了 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/

相关文章:

javascript - 在一组比赛中调用一个事件

javascript - 如何使用 Bootstrap Tab Collapse 插件在标签内获取 h4 标签?

java - 无法验证提供的 CSRF token ,因为找不到您的 session

spring-mvc - RequestParam 从选择选项 html 表单中获取数组

jquery - 跨域ajax的问题

javascript - 可以将嵌入的 swf 从一个标签移动到另一个标签吗?

javascript - 如何使用三元运算符选择函数

spring - 在本地工作但不在生产环境中使用 UnsatisfiedDependencyException 创建名称为 'webSecurityConfiguration 的 bean

ruby-on-rails - flash和跨域问题

jquery - 定义Content-Type时跨域jQuery AJAX失败