Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
C# 对ASP.NET WEB API的Ajax调用返回200状态代码错误_C#_Jquery_Asp.net_Ajax_Asp.net Web Api2 - Fatal编程技术网

C# 对ASP.NET WEB API的Ajax调用返回200状态代码错误

C# 对ASP.NET WEB API的Ajax调用返回200状态代码错误,c#,jquery,asp.net,ajax,asp.net-web-api2,C#,Jquery,Asp.net,Ajax,Asp.net Web Api2,目标是进行ajax调用,删除存储的用户搜索 方法如下所示: [HttpPost] [ActionName("DeleteStoredSearch")] public HttpResponseMessage DeleteStoredSearch(StoredSearch request) { _service.StoredSearchDelete(request.StoredSearchId); return new HttpRes

目标是进行ajax调用,删除存储的用户搜索

方法如下所示:

    [HttpPost]
    [ActionName("DeleteStoredSearch")]
    public HttpResponseMessage DeleteStoredSearch(StoredSearch request)
    {
        _service.StoredSearchDelete(request.StoredSearchId);

        return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
    }
    $.ajax({
        type: "POST",
        url: "https://" + domain + "/buyer/api/v1_0/FacetedSearchApi/DeleteStoredSearch",
        data: { "StoredSearchId": search_id },
        success: function (result)
        {
            console.log('Successfully called');
            $this_element.closest('.listing').remove();
            var thing = document.getElementById('searchcount').innerHTML;
            var thenumber = thing.match(/\d+/)[0]
            document.getElementById('searchcount').innerHTML = thing.replace(/\d+/, thenumber - 1);
        },
        error: function (exception) {
            alert("error:" + JSON.stringify(exception));
            console.log("error:" + JSON.stringify(exception));
        }
    });
ajax调用如下所示:

    [HttpPost]
    [ActionName("DeleteStoredSearch")]
    public HttpResponseMessage DeleteStoredSearch(StoredSearch request)
    {
        _service.StoredSearchDelete(request.StoredSearchId);

        return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
    }
    $.ajax({
        type: "POST",
        url: "https://" + domain + "/buyer/api/v1_0/FacetedSearchApi/DeleteStoredSearch",
        data: { "StoredSearchId": search_id },
        success: function (result)
        {
            console.log('Successfully called');
            $this_element.closest('.listing').remove();
            var thing = document.getElementById('searchcount').innerHTML;
            var thenumber = thing.match(/\d+/)[0]
            document.getElementById('searchcount').innerHTML = thing.replace(/\d+/, thenumber - 1);
        },
        error: function (exception) {
            alert("error:" + JSON.stringify(exception));
            console.log("error:" + JSON.stringify(exception));
        }
    });
我得到以下错误:

错误:{“readyState”:0,“responseText”:“status”:0,“statusText”:“error”}

需要一些帮助

编辑:

该调用是跨域调用,我收到以下消息:

XMLHttpRequest无法加载https://“CAN'TSHOWTHIS”/FacetedSearchApi/DeleteStoredSearch。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“TSHOWTHIS.com”


web.config
部分添加以下代码

<httpProtocol>
  <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
      <add name="Access-Control-Allow-Headers" value="Content-Type" />
      <add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS" />
  </customHeaders>
  </httpProtocol>

这是跨域请求吗?检查控制台以查找确切的错误您如何知道它是
200
?它是一个跨域请求。它是200,因为我检查了请求的状态代码。可能是重复的,我用适当的来源替换了来自
“*”
,它就像一个符咒。非常感谢。