views:

31

answers:

1

i'm trying to send the value of the search textbox via jquery on keydown to the php page so that it can display the results containing the search keyword. however, the php page is not reading $_POST of the input textbox [not button].

html:

.keydown(function() {
     //create post data
      var postData = { 
    "bsearch" : $(this).val()
     };

      //make the call
      $.ajax({
       type: "POST",
       url: "quotes_in.php",
      data: postData, //send it along with your call
      success: function(response){
    $("#bquote").html(response);
    }
    });
})

. . . 

 <!-- Begin Search -->
        <div id="search" style="display:none;">
                <input type="text" class="bsearch" name="search" value="Search" />
        </div>
 <!-- End Search -->

php:

include_once "inc/class.quotes.inc.php";
$quotes = new Quotes($db);


if (isset($_POST['search'])) 
    //$quotes->searchQuotes();
    echo 'Searching. . ';
else
    $quotes->displayQuotes();

it seems it is not reading the $_POST['search'] because it does not echo the text 'Searching. .' but instead goes to the else part and displays the quotes.

i tried this code to find out what is happening:

echo "<pre>";
print_r($_POST);
echo "</pre>";

this displays an empty array. what am i doing wrong?

+1  A: 
Shuja Shabandri
thanks for pointing this out!
fuz3d