AJAX and PHP question

Associate
Joined
4 Mar 2007
Posts
315
Location
United Kingdom
I am experimenting with AJAX and have a table set up with a drop down.
The table is filled from a database handled by the php upon the state of a GET.
I wish to change the GET in the url upon changing the selection from a drop down. How would I go about sending a request to the server to change the GET in the url to update the table without completely refreshing the page?

Regards,
 
Associate
Joined
15 Dec 2008
Posts
126
No clue about PHP, but this is toughly translated from what I'd do in .Net MVC with jQuery:

1. Make a view that only contains the table (say, table.php).

2. Include it inside a <div id='myTable'> on the parent view (say, main.php).

3. Have the browser load with $('#myTable').load('table.php?...'); to reload the table client side.
 
Soldato
Joined
12 Jan 2004
Posts
3,172
Location
Brighton
Code:
$('#mydropdown').bind('change', function(e) {
   var val = $(this).val();
   $.ajax('myselection.php', {'item' : val}, function(data) {
      var mytable = $('#mytable');
      mytable.empty();
      for (var counter = 0; counter < data.length; counter ++) {
         $('<td>'+data[counter]+'</td>').appendTo($('<tr />').appendTo(mytable));
      }
   });
});


Hows that?

EDIT : Something like that anyway
 
Back
Top Bottom