I'm just learning jquery , The thing is that how can I make jquery and php contact each other in one single page ? if there is an example I really appreciate it!

Member Avatar

Depends on the direction of communication and whether you want communication after the page has left the server.

You can include php inside js scripts for scripts running on page load...

var myVar =<?php echo $hisVar;?>;

However, you can't do the reverse as javascript is run after the info has left the server, so can't communicate with PHP. So this...

<?php $hisVar = myVar; ?>

can't work - well it couldn't anyway - but we CAN use AJAX.

var req = $.ajax({
        url: 'phpfile.php',
        method: 'get',
        data: {isbn: myisbn},
        dataType: 'json'

This is now the standard method of connecting client and server-side without page reload.

I agree with diafol's answer above. PHP runs first on the server then the javascript runs in your browser.