我正在使用MVC.net並將發佈數據發送到我的Web API 2控制器。我不斷收到500內部服務器錯誤消息。儘管啓用了CORS,但無法使用ajax發佈到其他域
我想發佈到另一個域,如果重要?我有2個visual studio實例正在運行,一個充當客戶端,另一個充當服務器。我已經啓用了CORS。
GET的工作正常,但現在我試圖發佈。
我的「服務器」上的控制器是
[HttpPost]
[Route("api/cms/")]
public IHttpActionResult Post([FromBody]int accountId, [FromBody]string content, [FromBody]string paneId, [FromBody]string url)
{
//content
}
「客戶」我使用的JavaScript是
function ajaxStart(type, url, data, successDelegate, failDelegate, errorDelegate) {
$.ajax({
type: type.toUpperCase(),
url: url,
contentType: "application/json;charset=utf-8",
data: data,
dataType: "json",
success: function (response) {
successDelegate(response);
},
failure: function (e) {
failDelegate(e.statusText);
},
error: function (e) {
errorDelegate(e.statusText); //always hit
}
})
}
的數據與(我故意用廢話創建字符串只是爲了確保格式化沒有任何問題)
var data = JSON.stringify({ accountId: 1, paneId: "_selectedPaneNumber", url: "_url", content: "content" });
而'header'view in谷歌Chrome瀏覽器開發工具顯示:
我不知道我做了什麼錯。
[2的WebAPI POST單字符串參數不工作呢](的可能的複製https://stackoverflow.com/questions/37842231/webapi-2-post-with-single-string-parameter-not-wokring ) – Igor
我已經完全更新了我的帖子,現在它不是一個笨蛋。 – MyDaftQuestions