简体   繁体   English

数据格式Jquery Ajax发布跨域调用Asp.Net MVC方法

[英]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.

相关问题 在ASP.NET MVC中发布序列化的ASP.NET模型和带有单个Jquery Ajax调用的文件 - Post a serialized ASP.NET Model and a file with single Jquery Ajax call in ASP.NET MVC Ajax调用asp.net POST方法 - Ajax call to asp.net POST method Ajax POST 对象跨域 asp.net 核心控制器,net::ERR_ABORTED 405(方法不允许) - Ajax POST object to cross domain asp.net core contoller, net::ERR_ABORTED 405 (Method Not Allowed) 如何在C#ASP.Net MVC中为datatable.net ajax调用格式化数据 - How to format data in C# ASP.Net MVC for datatable.net ajax call ASP.NET MVC中的AJAX POST方法中未发生重定向 - redirection not happening in AJAX POST method in ASP.NET MVC 对ASP.NET MVC操作方法的JQuery Ajax调用-“内部服务器错误?” - JQuery Ajax Call towards ASP.NET MVC action method - “Internal Server Error ?” 如何在asp.net MVC中使用jQuery Ajax在方法中调用字符串 - How to call a string in a method using jquery ajax in asp.net mvc 向ASP.NET MVC 5.0控制器方法添加参数导致JQuery数据表Ajax调用挂起 - Adding arguments to ASP.NET MVC 5.0 Controller Method Causes JQuery Datatable Ajax Call to Hang jQuery 通过 Ajax 在 ASP.NET MVC C# 中调用 Action 方法 - jQuery to call Action Method in ASP.NET MVC C# by Ajax 通过ASP.NET MVC应用程序中的Ajax发布将大型JSON数据发送到操作方法中的问题 - Issue in sending large JSON data to action method through ajax post in asp.net mvc application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM