svenson svenson - 1 year ago 69
PHP Question

Ajax display results in already created div

I have index.php like main page and I have sidebar.php included in index.php. In index.php I have div

with some content already loaded.. and in sidebar.php a I have

<form id="search" method="post" action="" >
<input type="search" name="search" id="search">
<input type="submit" name="search" id="search" class="btnButton" value="Search"/>

so how can I display my search result in div
when I click on submit?

Answer Source

Call the search.php from main page using Jquery ajax. make sure u reference the jQuery library.

//Main Page
<form id="search" method="post" action="" >
      <input type="text" name="search" id="search"> 
      <input type="submit" name="search1" id="search1" class="btnButton" value="Search"/>

<div id="content"></div>


    //jquery click event
    $("#search").live("click", function(e){

       //disable default form submit postpage

       //make ajax call to the search.php parsing the search textbox value as query string
       $.get("search.php?s="+$("#search").val(), function(result){

            //Result will be dumped in the div





//Search PHP Script search.php

//Get the search String
$string = $_GET["s"];

//DO search query and echo it on this page.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download