1 votes

How to send JavaScript string to php

Not able to send a string from Ajax at PHP, this is my code.

//JavaScript

function start(){
  var move ="start";
  $.ajax({
    url:'index.php',
    type:'post',
    dataType:'text',
    data:'move'
  })
}

//php

<?php
  $code= $_POST['move'];
  var_dump($code); 
  switch ($code) {
        case 'start':
        echo "from start";
        break;
    case 'right':
        echo "from right";
        break;
    default:
        break;
  }
?>

In the console of the browser in response gives me this line, from what I understand, comes the query to PHP but no string, for compare in the switch.

string(0) ""

it all begins with a:

<button id="start" onclick="start();">inicio</button>

I hope you can help me Thanks.

2voto

Lud Osorio Points 171
<pre><code></code><p>I hope it will serve you, greetings,</p></pre>

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X