0

How can I get my values from json_encode with a callback function

data({
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
});

I want to get the values of my response body so that I will know if there's an error using PHP. I need to have a callback function to easily get my values via javascript.

8
  • What happens when you var_dump($response) ? Commented Jan 21, 2012 at 17:34
  • @AdamPointer I've edited my code above to show more details Commented Jan 21, 2012 at 17:44
  • getThis({"data":"1234"}); is JavaScript, not JSON, so obviously json_decode won't work. What are you trying to do exactly? Commented Jan 21, 2012 at 17:58
  • @netcoder Yeah, but I'm working on a server to client app. Calling the data on the server with a callback via Javascript. But the real problem is in here (stackoverflow.com/questions/8953195/…) that's why I want to manipulate this data to know if there's any response error. Commented Jan 21, 2012 at 18:06
  • As said in the other question's answer, the HTTP request response code will tell you if there's an error, not the response body. Just check the HTTP response code, no JSON parsing required. Commented Jan 21, 2012 at 18:08

1 Answer 1

2

Assuming you meant var_dump($response) not var_dump($result) and I understand you properly, json_encode has converted your function to a string as you cannot convert a function to json and vice versa only arrays, objects and primitives such as strings.

This maybe a help... PHP json_encode and javascript functions

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but maybe Im gonna skip this. Nice reference for the future need :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.