2014-02-17 147 views
0

這是我的表單,我只需要在ajax中提交這個表單。我想只是與阿賈克斯在提交簡單的HTML 我總代碼工作正常,我必須與阿賈克斯沒有別的用Ajax提交表單

 <html> 
    <head> 

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script> 
    <script> 
$(function() { 
$("#register-form").validate({ 
    rules: { 
     name: "required", 
     email: { 
      required: true, 
      email: true 
     }, 
     Budget: { 
      required: true, 
     }, 
     phone:"required", 
     budget:"required", 
     agree: "required" 
    }, 
    messages: { 
     name: "Please enter your Name", 
     email: "Please enter a valid Email address", 
     phone: "Please enter a valid Phone Number", 
     Budget: "Please Select a Budget", 
     agree: "Please accept our policy" 
    }, 
    submitHandler: function(form) { 
    alert("success"); 
     form.submit(); 
    } 
}); 
}); 
    </script> 
    </head> 
    <body> 
    <form action="" method="post" id="register-form" novalidate="novalidate"> 
     <div class="label">Name</div><input type="text" id="name" name="name" /><br /> 
     <div class="label">Email</div><input type="text" id="email" name="email" /><br /> 
     <div class="label">Phone Number</div><input type="text" id="phone" name="phone" /><br /> 
     <div class="label">budget</div> 
     <select id="Budget" name="Budget"> 
      <option value="">select</option> 
      <option value="1">0-100</option> <!-- first option contains value="" --> 
      <option value="2">100-200</option> 
      <option value="3">200-300</option> 
     </select> 
     <br /> 
     <div style="margin-left:140px;"><input type="submit" name="submit" value="Submit" /></div> 
    </form> 
</body> 

這是我的形式我只需要在AJAX提交此提交。我只想提交與簡單的HTML中的AJAX 我的總代碼工作正常我必須提交與AJAX沒有其他

+0

你嘗試過什麼嗎? –

+0

沒有什麼只是做一個處理函數提交我必須做提交ajax – user3292597

+0

顯示一些辛苦工作和代碼爲ajax我們將很樂意幫助您' –

回答

1

您可以在submitHandler像定義AJAX調用;

submitHandler: function(form) { 
     $(form).ajaxSubmit({ 
      url:"echo/html", 
      type:"GET", 
      success: function(response){ 
      alert(response) 
      } 
     });   
} 

這裏是工作提琴:http://jsfiddle.net/2fC3Z/

0

創建一個JavaScript函數,並在窗體上onsubmit事件調用它。

在功能

,連載的形式數據,一個JSON數組,並將其發佈到你的頁面要使用簡單的Ajax調用

+0

批准的代碼?如果你提供一些代碼會更好 –

0

使用代碼類同下面的一個

 $.ajax({ 
      type: "PUT", 
      url: "http://xxxxxx.com/post.php", 
      contentType: "application/json", 
      data: JSON.stringify({ 
       name: "Tricia", 
       age: 37 
      }), 
      dataType: "text", 
      success: function(response){ 

       // Put the plain text in the PRE tag. 
       $("#putResponse").text(response); 

      }, 
      error: function(error){ 

       // Log any error. 
       console.log("ERROR:", error); 

      }, 
      complete: function(){ 

       // When this completes, execute teh 
       // DELETE request. 
       makeDELETERequest(); 

      } 
     });