![](/img/trans.png)
[英]Post a serialized ASP.NET Model and a file with single Jquery Ajax call in ASP.NET MVC
[英]Data Format Jquery Ajax Post Cross Domain Call Asp.Net MVC method
我正在尝试从http到https跨域的$ .ajax发布MVC调用。
客户端
enter code here
$.ajax({
type: 'post',
crossDomain: true,
url: 'https://localhost/views/Member/VerifyEmail',
beforeSend: function () { alert('I am sending'); },
data: '{name:"John"}',
dataType: "json",
success: function (data) { pdata = data; }
});
服务器端
[RequireHttps]
[HttpPost]
public string VerifyEmail(string name){
return "got it"
}
我已经将Access-Control-Allow-Origin添加到web.config
因此可以很好地建立调用。 现在问题出在服务器端,我得到了变量名= null
我还检查了调试,发现数据实际上已经发送到服务器了
HttpContext.Request.Form
{%7bname%3a%22hello%22%7d}
[System.Web.HttpValueCollection]: {%7bname%3a%22hello%22%7d}
问题是如何从Web方法中检索它?
%7bname%3a%22hello%22%7d这是HTML实体字符串,请解码该字符串,然后解析为JSON。
我认为您可以将通话更改为
$.ajax({
type: 'post',
crossDomain: true,
url: 'https://localhost/views/Member/VerifyEmail',
beforeSend: function () { alert('I am sending'); },
data: 'John',
dataType: "text",
success: function (data) { pdata = data; }
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.