Im trying to send data from ajax to php.

When I´m trying to alert it, it works perfectly, but when i tried to post the data it didnt work.

My Ajax

function onBtnClick(event){
    var nah = JSON.stringify(points);
    alert(nah);
    $.ajax( {
      url:"../php/points.php",
      type:'post',
      data: {point:nah},
      success: function(response){
          window.location = "../php/points.php";
      }

  })

  }

Points that im trying to post

 points[currentid] = {id: currentid, x: event.offsetX, y: event.offsetY};
  currentid++;

Php Code

if(isset($_POST['point'])){
        $user = $_POST['point'];

        $decoded = json_decode($user, true);

        var_dump($decoded);

        echo $decoded;
    }

0 Answers