JQuery updates div using php script

I have absolutely no idea how to do this, so I'm going to go and ask.

What I want to do is update the contents of the div using a PHP script. I have an external file called send.php.

So, I have a div like:

<div class="classname"> </div> 

And I want to send data to this send.php file, and then update this div with whatever the result of the PHP script. It can be done?

+4
source share
3 answers

For simple ajax calls, I usually prefer to use $. load , because its grammar is extremely short. Passing parameters as an object (key / value pairs) will force it to use a POST request:

 <a href="no-script.php" class="something">Click!</a> $(document).ready(function() { $('a.something').click(function(e) { //prevent the href from being followed e.preventDefault(); //inject div.classname with the output of send.php $('div.classname').load('send.php', {param1: 'foo', param2: 'blah'}); }); }); 

If you don't need POST, you can simply add your parameters to the query string:

 $('div.classname').load('send.php?param1=' + param1 + '&param2=' + param2); 
+5
source
 <a href="#">click</a> <script> $(function() { $("#refresh").click(function(evt) { $("#classname").load("send.php?data=someData") evt.preventDefault(); }) }) </script> <div id="classname"> </div> 

Some documentation to read:

0
source

Absolutely! Take a look at this post for instructions on how to use jQuery ajax. Then you will want to call

 $.(".classname").append("Whatever results you get"); 

To fill a div.

Good luck

0
source

All Articles