samedi 5 avril 2014

c# - appel AJAX toujours en erreur au lieu des résultats - Stack Overflow


I have a button in a view that is successfully calling into this javascript function that I've created (I've debugged into it successfully).


However, when it gets to the AJAX portion it always returns with my alert(error message).


I want the AJAX to direct my parameters to the ResultsController 's Index method.


var params =
{
state: "California",
county: "Los Angeles County",
city: "Los Angeles",
lastname: "Doe",
firstname: "John"
}
//^ Verified! Params is populated successfully

$.ajax({
url: '/Results/Index',
data: JSON.stringify(params),
contentType: 'application/json',
type: 'POST',
success: function () {
if (data) {
alert('life is good');
}
},
complete: function () {
// something
},
error: function () { alert('An error has occured. '); }
});

Here's the controller method header that I'm trying to reach (in the ResultsController)


public ActionResult Index(string state, string county, string city, string lastname, string firstname) 



success callback should have a parameter data. See following:


success: function (data) {
if (data) {
alert('life is good');
}
},


I have a button in a view that is successfully calling into this javascript function that I've created (I've debugged into it successfully).


However, when it gets to the AJAX portion it always returns with my alert(error message).


I want the AJAX to direct my parameters to the ResultsController 's Index method.


var params =
{
state: "California",
county: "Los Angeles County",
city: "Los Angeles",
lastname: "Doe",
firstname: "John"
}
//^ Verified! Params is populated successfully

$.ajax({
url: '/Results/Index',
data: JSON.stringify(params),
contentType: 'application/json',
type: 'POST',
success: function () {
if (data) {
alert('life is good');
}
},
complete: function () {
// something
},
error: function () { alert('An error has occured. '); }
});

Here's the controller method header that I'm trying to reach (in the ResultsController)


public ActionResult Index(string state, string county, string city, string lastname, string firstname) 


success callback should have a parameter data. See following:


success: function (data) {
if (data) {
alert('life is good');
}
},

0 commentaires:

Enregistrer un commentaire