I have a button on my webpage that triggers a JavaScript function I've created. I have successfully debugged into this function.
However, whenever the function reaches the AJAX part, it always returns with an error message alert.
I aim for the AJAX call to send my parameters to the Index method in the ResultsController.
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. '); }
});
Below is the header of the controller method I am attempting to access (in the ResultsController)
public ActionResult Index(string state, string county, string city, string lastname, string firstname)