jquery - Ajax Post Throwing Error -


the ajax post hits server , delivers correct information, though works still hitting error function. ready state 0, says isn't making request.

            var serviceurl = '/contactform/firstajax';             $.ajax({                 type: "post",                 url: serviceurl,                 data: json.stringify(forminfo),                 contenttype: "application/json; charset=utf-8",                 datatype: "json",                 success: function () {                             alert("worked");                         },                  error: function (xhrequest, errortext, thrownerror) {                     alert("failed process correctly, please try again" + "\n xhrequest: " + xhrequest + "\n" + "errortext: " + errortext + "\n" + "thrownerror: " + thrownerror);                  }             }); 

the error message is:error msg

my controller looks this:

    [httppost]     [actionname("firstajax")]     [outputcache(nostore = true, duration = 0, varybyparam = "*")]     public jsonresult firstajax(contactform contactform)     {                     return json("works", jsonrequestbehavior.allowget);     } 

there's error in ajax post method or controller. if leave ajax method is, can modify controller to:

[httppost] [actionname("firstajax")] [outputcache(nostore = true, duration = 0, varybyparam = "*")] public jsonresult firstajax() {                 var posteddata = new streamreader(request.inputstream);     var jsonencoded = posteddata.readtoend(); //string json     //decode json , work.      return json("works", jsonrequestbehavior.allowget); } 

if don't want change controller, need change javascript to:

var serviceurl = '/contactform/firstajax'; $.ajax({         type: "post",         url: serviceurl,         data: { contactform: json.stringify(forminfo) },         contenttype: "application/json; charset=utf-8",         datatype: "json",         success: function () {                      alert("worked");                 },         error: function (xhrequest, errortext, thrownerror) {             alert("failed process correctly, please try again" + "\n xhrequest: " + xhrequest + "\n" + "errortext: " + errortext + "\n" + "thrownerror: " + thrownerror);          }     }); 

hope helps.


Comments