I am using Jquery to make some ajax request :
$('#my-btn').click(function() {ldelim}
var comment = $('#textarea').val();
var m = {$id};
var data = {ldelim}
comment: $('#textarea').val(),
m: {$id}
{rdelim};
$.post('index.php?page=page',data,function(callback_data){ldelim}
var content = $('div.my-btn').html();
$('div .comments').append(content);
...
alert(callback_data);
{rdelim});
{rdelim});
(The reason of that {rdelim} or {$id} is that I am using the template engine Smarty.)
The processing of my php code works just fine : the bdd is correctly implemented but the alert of the callback sends an '404', preventing me from echoing a data number from my php code. (When I call for an echo($data) in my php code, I get the alert of $data+404).
Does anyone has an idea ?
Best, Newben
The callback for jQuery's .post()
is only for success (HTTP status code 2XX) responses. To have a callback for 404's you need to use .ajax()
:
$.ajax({
type: 'POST',
url: 'index.php?page=page',
data: data,
success: function(callback_data) {
// ...
},
error: function(jqXHR, textStatus, errorThrown) {
// ...
}
});
Please see http://api.jquery.com/jQuery.post/ vs. http://api.jquery.com/jQuery.ajax/