【发布时间】:2017-01-02 05:13:02
【问题描述】:
我正在开发基于 Web 表单的 Web 应用程序表单,我想将 JSON 数据发送到一个 MVC 应用程序。两者都在不同的域上。
这是我的ajax方法:
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'http://localhost:52099/Controller/Index',
data: JSON.stringify(response.d),
dataType: 'jsonp',
success: function (response) {
alert("done");
},
error: function(e){
alert(e);
}
});
这是我的操作方法:
[HttpGet]
public ActionResult Index(ClientInformation model)
{
return(View);
}
Index 方法被调用,但我没有得到参数值。我需要做什么?这里有什么不对吗?
这是我作为 response.d 的数据:
[{"Id":50345520,"FirstName":"Matthew","LastName":"McCauley","MiddleName":"","Suffix":null,"NPI":"1083043491","Address":"614 Esplanade St.","City":"Piscataway","State":"NJ","ZIP":"08854","Country":"United States","SubscriberFirstName":null,"SubscriberLastName":null,"SubscriberMiddleName":null,"SubscriberSSN":null,"SubscriberDOB":null,"SubscriberGender":null,"SubscriberSuffix":null,"SubscriberAddress":null,"SubscriberCity":null,"SubscriberState":null,"SubscriberZIP":null,"SubscriberCountry":null,"VisitDate":"\/Date(1483295400000)\/"}]"
还有
public class ClientInformation
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
public string Suffix { get; set; }
public string NPI { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZIP { get; set; }
public string Country { get; set; }
public string SubscriberFirstName { get; set; }
public string SubscriberLastName { get; set; }
public string SubscriberMiddleName { get; set; }
public string SubscriberSSN { get; set; }
public DateTime? SubscriberDOB { get; set; }
public int SubscriberGender { get; set; }
public string SubscriberSuffix { get; set; }
public string SubscriberAddress { get; set; }
public string SubscriberCity { get; set; }
public string SubscriberState { get; set; }
public string SubscriberZIP { get; set; }
public string SubscriberCountry { get; set; }
public DateTime? VisitDate { get; set; }
}
【问题讨论】:
-
什么是
response.d? -
其实这个ajax在另一个ajax调用成功下。在 response.d 我得到 json 数据。
-
对于初学者,您需要为跨源请求实现 CORS 服务器端。不难研究如何实现它
-
我需要做什么?
-
response.d里面有数据吗?你确定,试着做一个警报。如果您确定,请显示 response.d json 和ClientInformation的代码
标签: jquery json ajax asp.net-mvc