JSON parse failed
        Posted  
        
            by 
                Mesut
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mesut
        
        
        
        Published on 2013-10-24T09:48:42Z
        Indexed on 
            2013/10/24
            9:54 UTC
        
        
        Read the original article
        Hit count: 555
        
hello i haven an error abour ajax post success. after the success function i added code for lookin 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 comment the dataType: "json", my success function is working but i cant get the response.msg or response.myClass, if i dont comment it, success function is not working, here is the ajax code
$.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); 
    }   
 });
© Stack Overflow or respective owner