The code below just stopped working, although I haven't even touched this part of the file since last time it worked.
$.post(PATH_PRODUCTS_AJAX_URL, att, function(data) {
if(data.proper)
{
current_step = data.step;
$('#product_container').append('<div class="product_content">' + data.content + '</div>');
$('#product_container .product_content:last').animate({'left' : '-=460px'}, 200, 'swing');
}
else
{
alert('Not proper.');
}
}, 'json');
My debug process is as follows:
I've checked the URL and the input data - they're both fine. I use the data.proper variable to ensure that the data is alright; if the data isn't processed the right way, I should get the "Not proper" alert box - but now I don't. I've also tried with a random alert box outside the if statement, but nothing happens at all.
But if I remove the JSON parameter, I get the "Not proper" box. I could also see that the output data is all fine by alerting the data variable.
I've checked the involves files, and they're all UTF-8 encoded.
I have really no idea what I should do next. Any help appreciated.
Edit: (example data)
products.php:
$return['proper'] = true;
$return['step'] = 1;
$return['content'] = 'Hello';
$json = json_encode($return);
echo $json;
Response (note that this is only returned when the JSON parameter is excluded):
{"proper":true,"step":1,"content":"Hello"}
Could you try changing from the shorthand .post()
to an .ajax()
call to give you access to show the error:
$.ajax({
type: "POST",
url: PATH_PRODUCTS_AJAX_URL,
data: att,
dataType: "json",
success: function(data) {
if (data.proper) {
current_step = data.step;
$('#product_container').append('<div class="product_content">' + data.content + '</div>');
$('#product_container .product_content:last').animate({'left': '-=460px'}, 200, 'swing');
}
else {
alert('Not proper.');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Response text: "+XMLHttpRequest.responseText);
alert("Status returned: "+textStatus);
alert("Error thrown: "+errorThrown);
}
});