我正在研究基於webform的web應用程序表單,我想將JSON數據發送到一個MVC應用程序。兩者都在不同的域。使用ajax發佈JSON數據以跨域使用
這裏是我的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);
}
指數方法得到調用,但我沒有得到的參數值。我需要做什麼?這裏有什麼不正確的嗎?
這裏是我的數據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'? – CodingYoshi
實際上這個ajax是在另一個ajax調用的成功之下。在response.d我收到JSON數據。 – Ankita
對於初學者,您需要爲CORS服務器端實現跨越源的請求。不難研究如何實施它 – charlietfl