简体   繁体   中英

AJAX call always giving error instead of results

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');
    }
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM