jQuery.ajax没有执行成功的回调函数回调、函数、jQuery、ajax

2023-09-10 16:01:36 作者:懒得热情

我有一个JavaScript调用Ajax(jQuery.ajax),不执行成功的回调函数。

I have a JavaScript Ajax call (jQuery.ajax), that does not execute the success callback function.

$.ajax({
        url: target,
        contentType: 'application/json; charset=utf-8',
        type: 'POST',
        // type: 'GET',
        dataType: 'jsonp',
        error: function (xhr, status) {
            alert(status);
        },
        success: function (result) {
            alert("Callback done!");
            // grid.dataBind(result.results);
            // grid.dataBind(result);
        }
    });

我在Firebug看到,该请求被公布,并正确的结果在JSON的条款返回预期。什么是错的?

I see in firebug, that the request is posted and the correct result in terms of the json is returned as expected. What is wrong?

推荐答案

对于很多次,我也碰到过类似的问题,大部分时间的原因是一个畸形的JSON。尝试获得的结果为文本数据类型,看看这是否是你的问题。

For many times I have encountered similar problems and most of the time the reason was a malformed json. Try getting the result as text data type to see whether this is your problem.

另外,我想,如果你正在使用类似的参数要求和放大器; jsoncallback =在您的网址,因为你的数据类型是JSONP,而不是简单的JSON。

Also, I'd like to ask if you're using a parameter like "&jsoncallback=?" in your url, since your data type is jsonp instead of simple json.