ajax json request data to the controller, controller did not get the second parameter data.

Original link: http://www.cnblogs.com/DoudouZhang/p/7283650.html

This is my ajax request

$.ajax({
type: "post",
url: "/Login/Send",
data: { telephone: telephone.trim(), num: num }    { JsonInfo:JSON.stringify(params) },
async:false,
success: function (response) {
//Session过期
if (response.SessionExpire) {
location.href = "/Login/Index?SessionExpire=true";
return;
}
if (response.success) {
toastr.error("成功!");
}
else {
toastr.error("失败,请重试!");
}
}
});

controller thus received:

public ActionResult SendPhoneCheckCode(string telephone,string num)

But it is strange, you can take the value of the telephone runtime, but did not get the value of num, num is empty

The reason is unknown, but such modifications do, Ajax transmitting data: {JsonInfo: JSON.stringify (params)},

 var params = { telephone: telephone.trim(), num: num };

controller thus received:

public ActionResult SendPhoneCheckCode(string JsonInfo)
{
JObject jo = (JObject)JsonConvert.DeserializeObject(JsonInfo);
string telephone = jo["telephone"].ToString();
string info= jo["num"].ToString();

Reproduced in: https: //www.cnblogs.com/DoudouZhang/p/7283650.html

Guess you like

Origin blog.csdn.net/weixin_30764883/article/details/94798240