2010-01-31 72 views
0

我有下面的代码工作:jQuery的AJAX调用问题与GET

<script type="text/javascript"> 
    $(document).ready(function() { 
    // Initialise the table 
    $('#table_1').tableDnD({ 
    onDrop: function(table, row) { 
    $.tableDnD.serialize(); 

    location.href="test.php?" + $.tableDnD.serialize(); 
    } 
}); 

}); 
</script> 

它通过刷新location.href所有数据发送到下面的脚本:

<?php 
$table_1[] = $_GET['table_1']; 
$i = 0; 
if(!empty($table_1[0])){ 
    foreach($table_1 as $value) { 
     foreach($value as $row){ 
      $i++; 
      mysql_query("UPDATE mytable SET tableOrder='$i' WHERE id = '$row'"); 
     } 
    } 
} 

?> 

我会喜欢做的是使用ajax发送数据,这是我迄今为止,但它不工作:

<script type="text/javascript"> 
    $(document).ready(function() { 
    // Initialise the table 
    $('#table_1').tableDnD({ 
    onDrop: function(table, row) { 
    $.tableDnD.serialize(); 

    $.ajax({ 
     type: "GET", 
     url: "test.php", 
     data: "?"+$.tableDnD.serialize(), 
     success: function(html){ 
      alert("Eureka!"); 
     } 
    }); 

     } 
    }); 

}); 
</script> 

回答

2

change t YPE为 “POST”,丧失数据

OR

删除数据和CONCAT问号你有什么数据与URL

+0

这是有效的,但我不明白的是这样的: 我已经将ajax方法更改为POST,但将test_php文件中的$ _GET留下并且它可以工作。但是,如果我将其更改为$ _POST,它会停止工作? – kylex 2010-01-31 06:03:19

1

尝试改变:

data: "?"+$.tableDnD.serialize(), 

data: $.tableDnD.serialize(), 

不需要问号,jquery会为你做。