I don't see the issue.
With your $.post(), you set your dataType to 'json', and you're trying
to echo that. You'll probably just get 'Object object' as what's
alerted.

The 'after-post' will alert depending on your 'async' option setting.
By default all AJAX requests are sent asynchronous (hence, the 'A' in
AJAX). This means the request will just fire off, and the rest of your
script will continue to run (the after-post alert will go off
immediately without waiting for your AJAX response). When the response
is returned, your AJAX success callback is executed.
If you set 'async' to 'false', your script will wait until the AJAX
response is returned and the response callback  executed before it
will continue to the after-post alert.


On Feb 25, 12:46 am, Dakkar <[email protected]> wrote:
> Hi all,
>     I'm trying to use jQuery to send forms to a PHP script, but I've
> encountered some problems:
> - with $.post it works only with an alert just after the $.post
> instruction
> - with $.ajax it works without that alert only with async:false option
> - with both methods it works only with text datatype, but not json
> datatype
>
> the problem is about success (and error) callbacks that are not called
> properly, but the PHP script it's correctly called.
>
> CODE___
>                 /*$.post('include/saveconf.php', serialized, function(data, 
> status){
>                                                                               
>                                                   alert(data);
>                                                                               
>                                           }, "json");*/
>                 $.ajax({
>                         url: 'include/saveconf.php',
>                         async: false,
>                         type: 'POST',
>                         data: serialized,
>                         dataType: 'text',
>                         timeout: 1000,
>                         error: function(e){
>                                 alert("AJAX error!\n"+e.statusText);
>                         },
>                         success: function(data, status){
>                                 alert(data+"\n"+status);
>                         }
>                 });
>                 //alert('after-post');
> ___CODE
>
> Thank you in advance!
> Dakkar

Reply via email to