-1
Hello,
I need to get the data that are being passed via Ajax POST. But on the PHP side I’m not able to get past parameters.
My code Jquery
onSave: function(data, name) {
pixie.http().post('images/gravar_imagem.php', [{"name": name, "data": data}]).subscribe(function(response) {
console.log(response);
});
},
PHP
<?php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$name = $request->name;
$data = $request->data;
echo $name;
?>
appears the following error:
error: Syntaxerror: Unexpected token < in JSON at position 0 at JSON.parse () at Xmlhttprequest. u
text: "
↵Notice: Trying to get Property 'name' of non-object in C: xampp htdocs Pixie images gravar_imagem.php online 17
The error is inside the server, when there is an error on the server, the answer comes with html tags '<' when there is a php error will add tag with the error message. Therefore, your json contains html tags and becomes invalid due to unexpected tags.
– user125347
You send json pro php so you shouldn’t give a json_decode instead of Encode?
– fajuchem
@fajuchem error my I wrote wrong.. edited the question.
– Hejafe
@Tfm will check if you really have html tags on my Jason.
– Hejafe
What returns you console.log(Answer)?
– user125347
He doesn’t get to log in to the console.log(responds)
– Hejafe