[英]Jquery Ajax Not Passing Data to MVC Controller
我正在使用 jquery 的 ajax 方法將數據提交到 MVC controller。 但是,沒有數據傳遞到 controller。 我嘗試將 controller 預期的參數更改為字符串,並嘗試將 object 更改為字符串。 當它是一個字符串 null 時被傳遞,當它是一個 object 時,一個空的 object 被創建。
下面的代碼不言自明,但作為簡要說明,我正在創建一個帶有客戶數據的 javascript object 並將其作為 ajax 調用的一部分進行字符串化。
我知道以前有過這方面的帖子,我已經關注了這些帖子,但沒有成功。
非常感謝任何幫助。
var data = {
id: _CustomerID,
Address1 : _Address1,
Address2 : _Address2,
Address3 : _Address3,
Address4 : _Address4,
PostCode : _Address5,
EmailAddress : _Email,
PhoneNumber : _Phone,
postemail: _postemail,
postonly: _postonly,
emailonly: _emailonly
}
url = '@Url.Action("UpdateContactDetails", "MyAccount")';
$.ajax({
type: "POST",
dataType: "json",
data: JSON.stringify({CustomerObj: data}),
url: url,
contentType: "application/json"
}).done(function (res)
{
//process result
});
我用這個網站測試你的 Ajax 請求,你必須發送 object 參數而不是 JSON.stringify
Ajax 索取樣品代碼:
$.ajax({
type: 'POST',
dataType: 'json',
data: {
'name': 'morpheus',
'job': 'leader'
},
url: 'https://reqres.in/api/users'
}).done(function(response) {
console.log(response)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.