我有一個問題,我似乎無法弄清楚。我想提出以下Ajax調用:jquery ajax沒有發佈數據
var dataArray = { table: "Products" };
$.ajax({
url: uri,
type: "POST",
cache: false,
datatype: "json",
data: dataArray
})
.done(function(msg) {
alert("Data Saved");
})
.fail(function() {
alert("error");
});
我遇到的問題是,這似乎並沒有被髮送我有什麼在DataArray中,以我的Web API控制器,並保持着以下響應回來:
{"Message":"No HTTP resource was found that matches the request URI 'http://myURI'.","MessageDetail":"No action was found on the controller 'MYController' that matches the request."}
令我困惑的是我可以像這樣做一個GET,並且它返回數據正常。另外,如果我只是平板電腦追加查詢字符串到像這樣的
http://myURI?table=Products
然後POST工作正常。我可以這樣做,但我很好奇我在做什麼我的錯誤在上面。謝謝!
這就是我的控制器。我只是基本上試圖驗證我現在可以得到它。
public void Post(string table)
{
string beingHit = "We did it!";
}
'datatype:json,' - 你需要引用JSON位 - 但是如果你說你可以在你的查詢字符串上有一個GET變量時正確地POST到你的端點,你需要評估你的API控制器正在處理請求方法 - 並在此處發佈一些代碼,以便我們可以爲您提供幫助 –
您還需要對數據進行jsonify。 $ .ajax不會爲你自動完成。使用類似https:// github的東西。com/douglascrockford/JSON-js –
@scrowler請參閱http://stackoverflow.com/questions/13735869/datatype-application-json-vs-json – Musa