目標は、ユーザーのストアド検索を削除するajax呼び出しを行うことです。200のステータスコードのエラーを返すASP.NET WEB APIへのAjax呼び出し
方法は次のようになります。
[HttpPost]
[ActionName("DeleteStoredSearch")]
public HttpResponseMessage DeleteStoredSearch(StoredSearch request)
{
_service.StoredSearchDelete(request.StoredSearchId);
return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
}
AJAX呼び出しは、次のようになります
$.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));
}
});
私は次のエラーを取得する:
error:{"readyState":0,"responseText":"","status":0,"statusText":"error"}
いくつかの助けがapreciatedされるだろう。
EDIT:
呼び出しがクロスドメインである、と私は、次のメッセージが出ます:
XMLHttpRequest cannot load https://"CAN'TSHOWTHIS"/FacetedSearchApi/DeleteStoredSearch. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin http://CAN 'TSHOWTHIS.com' is therefore not allowed access.
これは相互ドメインのリクエストですか?コンソールをチェックして正確なエラーを見つけてください –
あなたはそれが '200'であることをどのように知っていますか? –
これはドメイン間の要求です。私はリクエストのステータスコードをチェックしたので、200です。 –