Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
即使在从服务器接收到响应之后,也会调用Jquery ajax请求错误回调而不是success_Jquery - Fatal编程技术网

即使在从服务器接收到响应之后,也会调用Jquery ajax请求错误回调而不是success

即使在从服务器接收到响应之后,也会调用Jquery ajax请求错误回调而不是success,jquery,Jquery,我正在使用jQueryAjax函数从我的Web服务中获取一些内容。收到来自服务器的响应,但每次调用错误回调而不是成功回调时 此错误在xhr中返回。错误: function (){if(l){var t=l.length;(function i(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&p.has(n)||l.push(n):n&&n.length&&"str

我正在使用jQueryAjax函数从我的Web服务中获取一些内容。收到来自服务器的响应,但每次调用错误回调而不是成功回调时

此错误在xhr中返回。错误:

function (){if(l){var t=l.length;(function i(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&p.has(n)||l.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=l.length:r&&(s=t,c(r))}return this}
以下是服务器响应的屏幕截图:

下面是我用来提出请求的代码:

function abcdef()
{
$.ajax({
    url: "http://192.168.61.129:8000/get-yt-access-token/",
type: "GET",
contentType:"application/json",
error: function(xhr, textStatus, errorThrown){
    alert("its error! " + xhr.error);
    },
success: function(data){
    alert(data);
    }
});
}

最后是CORS的问题!解决了!从同一台服务器上运行webservice和webpage,问题就解决了。

我们希望抛出错误,而不是xhr.error。xhr.error是一个函数。如果您确定web服务正在发送回json,请从控制台复制粘贴响应(而不是
alert(data)
)@mikakun嗯,他没有指定服务器必须返回json。他只是指定他正在发送json(但他从未实际发送json),您正在执行CORS请求。您的Web服务设置是否能够正确处理CORS请求?
contentType:“application/json”,
您的ajax调用需要json响应-从控制台复制粘贴响应(非警报(数据))