[英]Data Format Jquery Ajax Post Cross Domain Call Asp.Net MVC method
I am trying $.ajax post MVC call from http to https cross domain. 我正在尝试从http到https跨域的$ .ajax发布MVC调用。
Client Side 客户端
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; }
});
Server Side 服务器端
[RequireHttps]
[HttpPost]
public string VerifyEmail(string name){
return "got it"
}
I have added Access-Control-Allow-Origin to web.config
so the call can be established fine. 我已经将Access-Control-Allow-Origin添加到web.config
因此可以很好地建立调用。 Now the problem is on server side I got variable name = null 现在问题出在服务器端,我得到了变量名= null
I have also checked debugging and found the data has actually been send to server 我还检查了调试,发现数据实际上已经发送到服务器了
HttpContext.Request.Form
{%7bname%3a%22hello%22%7d}
[System.Web.HttpValueCollection]: {%7bname%3a%22hello%22%7d}
The question is how I could retrieve it from the web method? 问题是如何从Web方法中检索它?
%7bname%3a%22hello%22%7d这是HTML实体字符串,请解码该字符串,然后解析为JSON。
I think you can change your call to 我认为您可以将通话更改为
$.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.