c# - Javascript Modification to Allow Alert -


i have limited javascript experience , im trying modify script below show alert of success or failure after post attempt:

<script language="javascript" type="text/javascript">         $(function() {             $("form").submit(function(e) {                 $.post($(this).attr("action"),                         $(this).serialize(),                         function(data) {                     $("#result").html(data);                 });                 e.preventdefault();             });         }); </script> 

i know needs this:

success: function(){                     alert("edit successful");                 },                 error: function(){                     alert('failure'); 

but cant figure out how integrate without syntax errors. script performing post above code perform allow confirmation of success or failure occur:

@using (html.beginform("admin", "home", "post")) {     <div class="well">         <section>             <br>             <span style="font-weight:bold">text file destination:&#160;&#160;&#160;</span>             <input type="text" name="txt_file_dest" value="@viewbag.one">             <span style="color:black">&#160;&#160;&#160;example:</span><span style="color:blue"> \\pathpart1\\pathpart2$\\</span>             <br>             <br>             <span style="font-weight:bold">sql connection string:</span>             <input type="text" name="sql_connection" value="@viewbag.two">             <span style="color:black">&#160;&#160;&#160;example:</span> <span style="color:blue"> server=myserver;database=mydatabase;uid=myusername;pwd=mypswd</span>             <br>             <br>             <button class="btn btn-success" type="submit" name="document">save changes</button>         </section>     </div> } 

actionresult

public actionresult admin(string txt_file_dest, string sql_connection)         {             adminmodel values = new adminmodel();              if (txt_file_dest != null)             {                 values.savetxtdestination(txt_file_dest);             }              if (sql_connection != null)             {                 values.savesqlconnection(sql_connection);             }             viewbag.one = values.gettextpath();             viewbag.two = values.getsqlconnection();             return view();         } 

$.post(     $(this).attr("action"), // url     $(this).serialize(), // data     function(data) { //success callback function         alert("edit successful");     }).error(function() {         alert('failure');     }); 

that's shorthand ajax function can write as:

$.ajax({   type: "post",   url: $(this).attr("action"),   data:  $(this).serialize(),   success: function(data){     alert("edit successful");   },   error(function() {     alert('failure');   } }); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -