jQuery AJAX Success

后端 未结 6 1485
独厮守ぢ
独厮守ぢ 2021-01-17 10:08

I\'m using jQuery\'s $.ajax function to submit a form, which works, but the success is where I\'m having my problem. Here is my code:

$(\"#form\         


        
6条回答
  •  死守一世寂寞
    2021-01-17 10:34

    If you want to prevent the default behaviour( in this case the normal form submit), use preventDefault over return false; preventDefault will work even if there is a problem in the script which is above return false statement.

    The below code should work fine.

    $("#form").submit(function(e) {
       e.preventDefault();
        $.ajax({
            type: "POST",
            url: '/login/spam',
            data: formData,
            success: function (dataCheck) {
                if (dataCheck == 'value') {
                     //Do stuff
                }
            }
        });    
    });
    

    As gdoron mentioned, use console.debug/ alert to see what value is in the variables. Using firebug Net tab / fiddler will help you to understand what response you are getting from the server page.

提交回复
热议问题