提交没有重新加载页面的表单

时间:2013-08-18 18:01:02

标签: javascript html ajax forms

我不知道Ajax或PHP,但我想在没有页面刷新的情况下提交此表单,并且还希望在提交按钮旁边显示检查图标。我怎么能这样做?

<form id="form" action="" method="post">
    <input type="text" id="email" value="e-mail address" />
    <input type="submit" id="submit" name="submit" value="Submit" />
</form>

2 个答案:

答案 0 :(得分:0)

<script>
function xyz(){
var email_val=$('#email').val();
$.post("ajax.php",{"email":email_val},function(data){
  if(data) {
      $('#message').html('Data submit successfully');
      $('#email').val('');
    }
    else{
       $('#message').html('Failed');
    }
});
}

</script>


<form id="form" action="" method="post" onsubmit="xyz()">
   <input type="text" id="email" value="e-mail address" />
   <input type="submit" id="submit" name="submit" value="Submit" />
   <span id="message"></span>
</form>

ajax.php

if(isset($_REQUEST['email'])){
     //Your code here
}

答案 1 :(得分:0)

如果您不了解AJAX和PHP,但仍然需要提交没有重新加载页面的表单,请遵循本教程..做一些家庭作业

http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/