简体   繁体   English

在jQuery Ajax中获取“ parsererror”

[英]Getting “parsererror” in jquery ajax

Below is my AJAX code. 下面是我的AJAX代码。 Here I'm hitting a service with one value. 在这里,我要提供一种有价值的服务。 The service is getting called successfully, but it is not going into the success method. 该服务被成功调用,但是没有进入成功方法。 It is going into the error method only. 它仅进入错误方法。 In the error method it is giving parsererror and message: Unexpected token S 在错误方法中,它给出parsererror和消息: Unexpected token S

$.ajax({
    type: 'GET',
    url: 'http://domin.com:9000/ramsweb/rest/DetailRest/addOrderContacts/123456/' + customerId,
    success: function (data, status, xhr) {
        console.log(data);
        $("#loadingSpinner").hide();
    },
    error: function (jqXhr, textStatus, errorMessage) {
        $('.ErrorMsg').html('<h5>An error has occurred</h5>');
    },
    fail: function (data) {
        $('.ErrorMsg').html('<h5>data loading failed</h5>');
    }
});

jQuery AJAX functions by default will try to detect the type of response depending on other pieces of data in your request and response (headers etc.) 默认情况下,jQuery AJAX函数将尝试根据请求和响应中的其他数据(标题等)来检测响应的类型。

Most likely, your endpoint serves it as JSON thus telling jQuery to internally do a JSON.parse . 您的端点很可能将其用作JSON,从而告诉jQuery在内部执行JSON.parse However, your endpoint may be serving an error page instead of JSON which can cause parse errors like this. 但是,您的端点可能提供的是错误页面而不是JSON,这可能会导致解析错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM