JQuery Ajax function error when indeed there is a success -


my code calls error function, when hits action url supposed to. here jquery ajax code:

function contactdialog(action, controller) {      var url = '/' + action + '/' + controller;  $("#contactdialog").dialog({     autoopen: true,     hide: "fade",     show: "bounce",     height: $(window).height() / 2,     width: $(window).width() / 2,     title: "send email",     buttons: [{         text: "send", click: function () {             $.ajax({                 url: url,                                                      data: $("form").serialize(),                 context: this,                 contenttype: 'application/html; charset=utf-8',                 datatype: "json", //xml, json, script , html                 success: function () {                     $(this).dialog("close");                     sendconfirmmessage('msgsent');                                         },                 error: function () {                     sendconfirmmessage('msgnotsent');                 }             });         },     }, {         text: "cancel", click: function () {             $(this).dialog("close");         }     }] }); 

and here html/razor code:

<div style="margin-top: 10px; visibility: hidden;" id="contactlink">     <h3><a href="#" onclick="contactdialog('sendemail', 'sendmail')">contact me</a></h3> </div>  <div id="contactdialog" style="display: none;">     @using (ajax.beginform(null, null, new ajaxoptions { updatetargetid = "updaterdiv" }, new { id = "contactform" }))     {         @html.labelfor(model => model.subject)         @html.textboxfor(model => model.subject, new { @class = "aboutcontrols" })         <br />         @html.validationmessagefor(model => model.subject)         <br />         @html.labelfor(model => model.from)         @html.textboxfor(model => model.from, new { @class = "aboutcontrols" })         <br />         @html.validationmessagefor(model => model.from)         <br />         @html.labelfor(model => model.body)         @html.textareafor(model => model.body, new { @class = "aboutcontrols aboutcontroltxtarea" })         <br />         @html.validationmessagefor(model => model.body)         <hr />         <br /><br />     } </div>  <div style="display: none;" title="info" id="msgsent">     <p>thank you, message has been sent </p> </div> <div style="display: none;" title="info" id="msgnotsent">     <p>there error sending message, please try again </p> </div> 

here action method hit success, , call method, returns error, if doesn't call thisaction method. idea might wrong?

       public partialviewresult sendmail(emailmodel model)     {         string host = configurationmanager.appsettings.get("smtphost");         int port = convert.toint16(configurationmanager.appsettings.get("smtpport"));         string receiver = configurationmanager.appsettings.get("toaddress");         string password = configurationmanager.appsettings.get("password");          smtpclient smtp = new smtpclient(host, port);         smtp.credentials = new networkcredential(receiver, password);         smtp.enablessl = true;          mailmessage mailmsg = null;                      try         {             if (modelstate.isvalid)             {                 mailmsg = new mailmessage(model.from, receiver, model.subject, model.body);                 smtp.send(mailmsg);             }         }         catch (exception ex)         {             senderrormail("m@mail.net", "...", "exception", ex.tostring());         }          return partialview("_about");     } 

here might help.... , folks correct me if i'm wrong! seems success , error functions missing parameters. ideally should @ least pass dataas parameter.

$.ajax({             url: url,                                                  data: $("form").serialize(),             context: this,             contenttype: 'application/html; charset=utf-8',             datatype: "json", //xml, json, script , html             success: function (data) {                 console.log("here the data - ", data);                 $(this).dialog("close");                 sendconfirmmessage('msgsent');                                     },             error: function (data) {                 console.log("oops, didn't work - ", data);                 sendconfirmmessage('msgnotsent');             }         }); 

i log out info see progress. hope helps!


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -