0

成功とエラーを使用しているときに、AJAX を使用するフォームが更新されないようにするにはどうすればよいですか? 削除すると、false が返されます。関数の終了後、エラー (CLid の検証中にエラーが発生しました!) が表示され、ページが更新されますが、そのままにしておくと、ajax 関数が送信され、更新なしで true が返されます。さらに情報が必要な場合はお知らせください。ありがとう!


var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&company=' + phone + '&length=' + length + '$time=' + time + '&question' + question;

$.ajax({  
    type: "POST",  
    url: "contact_process.php",  
    data: dataString,  
    success: function() {  
       $('#search_contact').html("You're request for more information was submitted."); 
    },
    error: function() {
      $('#search_contact').html('Error validating CLid!');          
    } 
}); 


return false;

});
    
4

1 に答える 1

1

I suspect you are triggering this ajax request through an event on a form submission or link click or something.

If you are triggering the request from a link, ie:

<a href="contact_process.php" id="contactTrigger">Click me</a>

When you bind the event you need to call event.preventDefault(); on the event passed to the event handler to prevent the default behavior, ie:


$('#contactTrigger').click(function(event){
   event.preventDefault();
   //do your ajax stuff here.
});
于 2013-07-25T01:07:51.320 に答える