From jquery file to php:
$.post('http://botk-online.com/play2.php', {
'rate': Pontuacao.misses
});
How to modyficate this code to pass $data variable from php file to js external file and read it value.
From jquery file to php:
$.post('http://botk-online.com/play2.php', {
'rate': Pontuacao.misses
});
How to modyficate this code to pass $data variable from php file to js external file and read it value.
PHP
<?php
$result = array('data' => 'this is some data');
echo json_encode($result);
Javascript:
$.ajax({
url: 'http://botk-online.com/play2.php',
type: 'post',
data: {
rate: Pontuacao.misses
},
dataType: 'json',
success: function(json) {
alert('Data is: '+json['data']);
// Alerts: 'Data is: this is some data'
}
});
Use the success
handler, which will run if the code returns successfully:
jQuery.post( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )
Note the , success(data, textStatus, jqXHR)
above. For example:
$.post('http://botk-online.com/play2.php', {
'rate': Pontuacao.misses
}, function (data) {
doStuff(data);
}
});
http://api.jquery.com/jQuery.post/#example-5