Pass data from javascript to php using ajax when reloading the page

0

Good. I have the following code:

<head>
<script src="./jquery-latest.min.js"></script>
<script>
var jash = window.location.hash;
var url = "datos.php";

$.ajax({
    type: 'POST',
    url: url,
    data: {tuVariable:jash},
    success: exitoso
});
</script>
</head>
<body>
</body> 

Which is supposed to get the

  

hash

of this url

/src/list.html#access_token=533b45555555acf01e11f55b536a565b57531ad114461ae8736d6506a3

and then the content of the variable sends

  

jash

To the file datos.php which contains:

<?php
$url = isset($_POST['tuVariable']) ? $_POST['tuVariable'] : '';
echo $url;

Which does not work for me since it does not reflect any results I wait for your help and thank you for your time.

    
asked by BotXtrem Solutions 23.01.2018 в 02:53
source

1 answer

1

You are reversing the order, the key value of JQuery of data within Ajax is { clave : valor} , since PHP you access clave , then it should be

var jash = window.location.hash;
var url = "datos.php";
$.ajax({
    type: 'POST',
    url: url,
    data: {tuVariable:jash},
}).done(function(data){
    console.log(data);// return data php
});
    
answered by 23.01.2018 / 03:01
source