magicianiam magicianiam - 1 year ago 103
jQuery Question

ajax to retrieve data from another page after post

I know this is very easy, but i only know the DOM equivalent of this code. the very long one. i've already searched trough some of the questions here in stack but i cant seem to find the solution.

so basically i have this script:

function searchNow(str)
url: "search.php",
type: "POST",
async: false,
data: {"search": str},
success: function(data){


<td>Search: </td>
<td><input type = "text" name = "search" onBlur="searchNow(this.value)"> </td>

this will submit search to search.php to do a query search and retrieve the result and display it at id result.

i can do this easily using the old DOM ajax but then i wanna try using this jquery version instead since it is cleaner and maybe faster.

at my search.php
i have this:

$search = $_POST['search'];
return $search;

sadly i cant seem to return anything at all.

some input would be greatly appreciated, im already starting to be familiar with jquery ajax but only on the same page, not on inter page manipulation.

thank you,

Answer Source

Your PHP file should output the value. The ajax is going read that page and get it's content.

$search = $_POST['search'];
echo $search;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download