0

I am having some trouble posting data through AJAX. I created a small save script which determines in which table a POST must be saved (I am using a different form for each table):

$(function() 
{
    $( "#tabs" ).tabs().find( ".ui-tabs-nav" ).sortable({ axis: "x" });
});

function save(target)
{
    switch(target)
    {
        case "praktijk":
            $.ajax({                                                                                                           url: 'webscripts/admin/opslaan.php?type=praktijk',
                type: 'POST',
                data: $("#tabs-2").find('form').serialize(),
                success: function(){
                    alert("gegevens opgeslagen!");
                    $('#popup').dialog('close');
                }
            });
            break;
        case "persoonlijk":
            $.ajax({                                                                                   
                url: 'webscripts/admin/opslaan.php?type=persoonlijk',
                type: 'POST',
                data: $("#tabs-1").find('form').serialize(),
                success: function(){
                    alert("gegevens opgeslagen!");
                    $('#popup').dialog('close');
            }
        });
        break;
    case "vragen":
        $.ajax({
            url: 'webscripts/admin/opslaan.php?type=vragen',
            type: 'POST',
            data: $('#tabs-3').find('form').serialize(),
            success: function(){
                    alert("gegevens opgeslagen!");
                    $('#popup').dialog('close');
            }
        });
        break;
}

}

as you can see, I next determine it for the PHP script by using a GET variable that says which table it needs to save it in. But this doesn't work. The script appears to be crashing at this point. I am not sure where exactly it crashes.. the Firebug terminal doesn't show any obvious errors.

Does somebody know why it doesn't work?

4

2 回答 2

1

First of all, if you're using a different form for each table, why not send the right table name ('persoonlijk', 'vragen', etc.) with the form itself?

example:

<form ...>
<input type="hidden" name="target" value="persoonlijk" />
...
</form>

And in php:

<?php
if($_POST['target'] == 'persoonlijk') {
    // save in table 'persoonlijk'
} else {
   // save it somewhere else
}
?>

Furthermore, reading out a php var can not break your javascript, simply because you are working on the server, and javascript works in the browser. Please print out the get en post vars using print_r($_GET);, then explain what 'seems to break' means (what happens, what do you see (error messages and such)).

于 2012-08-22T11:10:59.877 回答
1

data:should contain some data. It should be a text or value and your code doesn't seems to have it correctly set up. I recommend you to use some var there.

于 2012-08-22T11:15:40.327 回答