2009-05-22 91 views
1

可能有人請給我一隻手,告訴我什麼是錯與此腳本?已發佈的答案無效。當我使用該代碼時得到的是整個HTML頁面被提交。這是我能從控制檯看到的。有人可以幫我嗎?謝謝。如何合併兩個jQuery函數


$(function() { 
    $('#add_customer_form').submit(function() { 
     var data = $(this).serialize(); 
     var url = $(this).attr('action'); 
     var method = $(this).attr('method'); 
     $.ajax({ 
      url: url, 
      type: method, 
      data: data, 
      dataType: 'json', 
      success: function(data) { 
       var $div = $('<div>').attr('id', 'message').html(data.message); 
       if(data.success == 0) { 
        $div.addClass('error'); 
       } else { 
        // START CHANGE 
        // you need to get `datastring` from somewhere 
        $.ajax({ 
         type: "POST", 
         url: "body.php?action=admCustomer", 
         data: dataString, 
         success: function(){ 
          $('#contact input[type=text]').val(''); 
          $div.addClass('success'); 
         } 
        }); 
        // END CHANGE 
       } 
       $('body').append($div); 
      } 
     }); 
     return false; 
    }); 
}); 
+0

它會很難理解你的問題...... – 2009-05-22 04:54:20

+0

那不是suprising .. – user109162 2009-05-22 05:42:20

+0

你們是不是要發送的信息? add_customer_form數據已被髮送。您嘗試發送了兩遍.... – 2009-05-23 00:33:15

回答

0
$(function() { 
    $('#add_customer_form').submit(function() { 
     var data = $(this).serialize(); 
     var url = $(this).attr('action'); 
     var method = $(this).attr('method'); 
     $.ajax({ 
      url: url, 
      type: method, 
      data: data, 
      dataType: 'json', 
      success: function(data) { 
       var $div = $('<div>').attr('id', 'message').html(data.message); 
       if(data.success == 0) { 
        $div.addClass('error'); 
       } else { 
        // START CHANGE 
        // you need to get `datastring` from somewhere 
        $.ajax({ 
         type: "POST", 
         url: "body.php?action=admCustomer", 
         data: dataString, 
         success: function(){ 
          $('#contact input[type=text]').val(''); 
          $div.addClass('success'); 
         } 
        }); 
        // END CHANGE 
       } 
       $('body').append($div); 
      } 
     }); 
     return false; 
    }); 
}); 
1

也許改變

var $div = $('<div>').attr('id', 'message').html(data.message); 

var $div = $('<div/>').attr('id', 'message').html(data.message); 

會做的伎倆?