2014-02-17 3 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> 

이 난 단지 아약스이를 제출해야 내 양식이다 아약스 아무것도 제출해야합니다. 난 그냥 간단한 HTML에서 아약스와 함께 제출하고 싶습니다 내 총 코드가 잘 작동 내가 잘 아약스와 함께 제출할 수있다

+0

아래에 코드 비슷한을 사용하여 여기에

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

는 작업 바이올린입니까? –

+0

아무것도 제출하기위한 처리기 기능을 만들 수 없다. 나는 아약스와 함께 제출해야만한다. – user3292597

+0

ajax를위한 노력과 코드를 보여 주겠다. 우리는 기꺼이 도와 줄 것이다. –

답변

0

자바 스크립트 함수를 만들고 양식 onsubmit 이벤트에서 호출하십시오. 기능에

, JSON 배열에 양식 데이터를에는 직렬화하고 당신은 submitHandler 등에 아약스 전화를 정의 할 수있는 간단한 아약스 호출

+0

withoud 코드를 승인 했습니까? 코드를 제공하면 더 좋을 것입니다. –

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(); 

      } 
     });