• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

php/jquery architecture question

Hi,
I have a couple of dropdown selects on the main screen, where users can define their search criteria and submit the search to the database. The result is a multipage table of data which I am showing under my selections. Now, is it possible to submit this form asynchronously and refresh only the table area when the result comes back ? Any examples ? Snippets ?
0
Rozamunda
Asked:
Rozamunda
  • 2
1 Solution
 
moagriusCommented:
there are several ways you could do it.

the return of the php script will be available in the first argument of the success function of the ajax call.

e.g.,
$.ajax({
  url : 'path/to/your/script.php',
  success : function(data){
    // data holds whatever script.php prints
    // so if it's your table already in html form, just set the html of a contianer element
    $('#container').html(data);
  }
});

// or even more simply...

$('#container').load('path/to/your/script.php');

Open in new window

0
 
RozamundaAuthor Commented:
How should I collect all the input data from my dropdowns ?
0
 
moagriusCommented:
you can collect the information from you form elements normally, or by using the val() method:

$('#my-select').val()

from there, you can pass variables with the 'data' property of the .ajax argument parameter object, and specify the method (get or post) with the 'type' property:
$.ajax({
  url : path/to/your/script.php',
  data : {
    some_value : $('#my-select').val()
  },
  type : 'POST',
  success : function(data){
    $('#container').html(data);
  }
});

// the php script would get $_POST['some_value'] set to the value of your dropdown

Open in new window

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now