使用jquery检查POST是否成功

Big*_*ppa 6 html asp.net-mvc jquery html5

我正在尝试编写将弹出的jquery函数,并说Post成功了!如果没有,邮政不成功!我如何使用try catch输入一些jquery?

@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.GetTextPath">
        <span style="color:black">&#160;&#160;&#160;Example:</span><span style="color:blue"> \\invincible\\chemistry$\\</span>
        <br>
        <br>
        <span style="font-weight:bold">SQL Connection String:</span>
        <input type="text" name="sql_Connection" value="@ViewBag.GetSqlConnection">
        <span style="color:black">&#160;&#160;&#160;Example:</span> <span style="color:blue"> Server=-</span>
        <br>
        <br>
        <button class="btn btn-success" type="submit" >Save Changes</button>
    </section>
</div>
Run Code Online (Sandbox Code Playgroud)

}

Big*_*ppa 5

所以我想出了我的答案。仅供将来尝试此操作的任何人参考,以下是我所做的。我把它放在@using (Html.BeginForm("Admin", "Home", "POST")) 上面。@Andrew 我确实尝试过你的,但我无法让它工作。感谢大家辛苦地帮助我。

<script language="javascript" type="text/javascript">
    $(function() {
       $("form").submit(function(e) {
          $.post($(this).attr("action"), // url 
  $(this).serialize(), // data
  function (data) { //success callback function
     alert("Edit successful");
  }).error(function () {
      alert('failure'); 
  });
             e.preventDefault();
          });
       });
</script>
Run Code Online (Sandbox Code Playgroud)


Raj*_*shi 0

$.ajax({
  url: 'post.html',
  success: function(){
    alert('success');
  },
  error: function(){
    alert('failure');
  }
});
Run Code Online (Sandbox Code Playgroud)