0

I'm trying to make some changes to the way jEditable handles errors. I have a PHP function which is returning:

echo "{'error':'ok', 'error_msg':'There was a problem'}";

in my javascript:

"callback": function( sValue, y ) 
                      {
                        if (sValue == "ok")
                        {
                          alert ("ok");
                        }
                        else
                        {
                          alert ("error");
                        }},

Now I keep getting the "error" alert on my screen - no matter what I try. Obviously the problem is at this line:

if (sValue == "ok")

but I'm not sure what it is supposed to be? I've looked at other examples on StackOverflow - but couldnt get one that answered my question.

Laurence
  • 58,936
  • 21
  • 171
  • 212

1 Answers1

2

Seems that you need to parse JSON and get error value from parsed object:

"callback": function (data, y) {
    var errorData = $.parseJSON(data);
    if (errorData.error == "ok") {
        alert("ok");
    } else {
        alert("error");
    }
},
antyrat
  • 27,479
  • 9
  • 75
  • 76