tags:

views:

46

answers:

2

I have the following code that works:

<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>

And it sends through a refresh location.href all the data to the following script:

<?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'");
        }
    }
}

?>

What I'd like to do is send the data using ajax, and this is what I have so far, but it's not working:

<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  A: 

change type to "POST" and lose the question mark in data

OR

remove data and concat what you have in data with url

Funky Dude
That works, but what I don't understand is this:I've changed the ajax method to POST but left the $_GET in the test.php file and it works. But if I change it to $_POST, it stops working?
kylex
+1  A: 

Try changing:

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

with

data: $.tableDnD.serialize(),

No need for the question mark, jquery does it for you.

Sarfraz