Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.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
Javascript 如何从HttpResponseMessage获取jqxhr.responseText?_Javascript_Jquery_Asp.net Mvc_Asp.net Web Api - Fatal编程技术网

Javascript 如何从HttpResponseMessage获取jqxhr.responseText?

Javascript 如何从HttpResponseMessage获取jqxhr.responseText?,javascript,jquery,asp.net-mvc,asp.net-web-api,Javascript,Jquery,Asp.net Mvc,Asp.net Web Api,这是我的服务器端代码 var response = new HttpResponseMessage { Content = new StringContent("FAIL FAIL"), StatusCode = HttpStatusCode.InternalServerError, }; response.Content.Headers.ContentType = new Medi

这是我的服务器端代码

        var response = new HttpResponseMessage
        {
            Content = new StringContent("FAIL FAIL"),
            StatusCode = HttpStatusCode.InternalServerError,
        };

        response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
        return Task<HttpResponseMessage>.Factory.StartNew(() => response);
但是当我使用firebug检查时,我的jqxhr.responseText是。 如何检索失败?

尝试以下操作:

var ajaxReult =   $.ajax({
        type: 'POST',
        url: 'someurl',
        data: somevalues,
        success: function (data) {
           // console.log(data);
        },
        error: function (jqxhr) {
           // console.log(jqxhr);
        }
    }).responseText;
console.log(ajaxReult);

你的url是跨域的吗?是的,它是跨域的。刚刚发现了一些东西。如果我使用firefox调试,我得到了null,但是如果使用IE,它显示了。你不能在跨域服务中使用AJAX调用POST类型。在跨域中只能进行GET调用,但它也应该遵循url中的jquery回调机制。else应该向jsonp添加数据类型。希望阅读本文能对您有更多帮助:
var ajaxReult =   $.ajax({
        type: 'POST',
        url: 'someurl',
        data: somevalues,
        success: function (data) {
           // console.log(data);
        },
        error: function (jqxhr) {
           // console.log(jqxhr);
        }
    }).responseText;
console.log(ajaxReult);