Pass values to PHP file with JSON

2

I have the following code that runs on any PC and requests information for a PHP file on a remote server.

How do I pass a parameter to this PHP using this my JSON code?

So I can send a die and get a processed render.

I know it sounds like something simple, but I could only run this scenario (HTML anywhere) and PHP (remote server) with this code. All other methods need to have all the files on the server.

HTML file + JS (Run on any computer running)

<script type="text/javascript"> 
var urlTeste = 'http://www.meuservidor.com/servidor.php?jsoncallback=?';
$(document).ready(function() {
//Mensagem enquanto não carrega a pagina
$('#resultado').html('Carregando...');

$.getJSON(urlTeste,null, function(data){
$('#resultado').html(data);   
});
}); 
</script>

PHP file (on server www.myserver.com/servers.php)

<?php
$var = date("d/m/Y H:i:s "); 
echo $_GET["jsoncallback"] . '(' . json_encode($var) . ');';    
?>

Thank you

    
asked by anonymous 25.06.2014 / 21:57

1 answer

3

Where you are passing null , pass an object:

$.getJSON(urlTeste, {chave: "valor", outro: "outro valor"}, function(data){
   $('#resultado').html(data);   
});

And in PHP:

<?php
$chave = $_GET['chave'];
$outro = $_GET['outro']; 
    
25.06.2014 / 22:16