I have an error about Jquery AJAX post success. After the success function I added code for looking for errors:
...
else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
...
on my PHP code:
echo json_encode(array('msg' => $msg, 'myClass' => $class));
returns back after my function. I checked in Firebug and it returns like,
Response like {"msg":"Kayd\u0131n\u0131z Ba\u015far\u0131l\u0131","myClass":"alert alert-success"}
HTML like {"msg":"Kayd\u0131n\u0131z Ba\u015far\u0131l\u0131","myClass":"alert alert-success"}
There is no JSON tab on firebug and on my AJAX code if I remove the dataType: "json",
(it's removed in the code below), my success function is working but I can't get the response.msg
or response.myClass
, if I don't comment it, success function is not working, here is the Javascript code which invokes the AJAX request:
$.ajax({
type: "POST",
url: "index.php?page=addItem&action=addItem&edit=true",
data: dataString,
success: function(response) {
$("#message").html(response.msg);
$("#message").addClass(response.myClass);
$("#itemForm").fadeOut("slow");
window.setTimeout('location.href = "index.php?page=addItem"', 1000);
}
});