0

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!

3
Contributors
2
Replies
34
Views
4 Years
Discussion Span
Last Post by Patrick Thomas
1

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'
    });
req.done(function(data){
        $('#msg').html(data.message);
    }); 

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.