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?
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:
And in php:
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)).