Json post for PHP

-1

Hello,

I need to get the data being passed via Ajax POST. But on the PHP side I can not get past parameters.

My 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; 
?>

the following error appears:

  

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 \ b> online 17

    
asked by anonymous 23.10.2018 / 22:03

1 answer

0

Posting to show how I solved the question you had:

On the OnSave method

onSave: function(data, name) {
        /*pixie.http().post('images/gravar_imagem.php', [{"name": name, "data": data}]).subscribe(function(response) {
            console.log(response);
  });*/

  $.ajax({
     type: 'POST',
     url: 'images/gravar_imagem.php',
     data: { data: data , name: name},
   }).success(function(response) {
      alert(response);
   });
  },
    
23.10.2018 / 23:20