1

In my php I'm getting

string(15) "[object Object]"

I'm posting from ajax an array consisting of:

ctx.imageData.push({name : file.name, value : this.result});

this.result is a base64 encoded image, taken from a js file reader.

How can I get the contents of object object in php?

7
  • simply var_dump it and see what it contains Commented Sep 17, 2013 at 10:41
  • @Laimoncijus — It contains string(15) "[object Object]" Commented Sep 17, 2013 at 10:43
  • "I'm posting from ajax" — How? You need to show enough code for people to be able to reproduce the problem. Commented Sep 17, 2013 at 10:43
  • @Quentin it doesnt matter how Im posting from ajax, the data is being sent. This is a problem with php Commented Sep 17, 2013 at 11:02
  • 1
    @panthro — [Object object] is how JavaScript (by default) stringifies an object. Since JavaScript is generating that string, the problem must be on the JavaScript side. Commented Sep 17, 2013 at 11:05

3 Answers 3

2

You probably try to push an object with javascript which is being cast to string. In PHP we get the result string(15) "[object Object]" because the string is actually [object Object] and you cannot get any information from it within PHP. You are making some mistake while passing the variable with javascript and you have to show us some more code to help you handle it.

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

Comments

1
ctx.imageData.push({name : file.name, value : JSON.stringify(this.result)});

And use json_decode in php.


jQuery does not have functionality of its own for that, you have to use the browser built-in version or json2.js from http://www.json.org

JSON.stringify() is available in all major browsers, but to be compatible with older browsers you still need that fallback.

4 Comments

json_decode just comes back with NULL, even with adding json_decode($myVar, true)
Try console.log(JSON.stringify(this.result)); and see what you get??
"data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQAB…1qMXeO+34oaxuI22+Ki/o8P/6Ht/SP/wCp9v4/P/b9nX/4vN/4dV6/Hf4ft/gs3p8N/j+zr//Z"
string(15) "[object Object]"
0

try json_decode() on the variable that you are getting in the php, and after that use var_dump to check its value

1 Comment

Try to elaborate better this answer ;)

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.