I have this page that lists info from my mysql database. It requires an ID I $get from the url from the current page I’m on: localhost/index.php?page=id
I wanted to add a search function so that the content dynamicly changes, as you type.
Its functional but the ID that I require does not get passed when using the search function, only on the first include.
My code looks like this (I omitted some irrelevant code and html):
<?php
$id = $_REQUEST['page'];
?>
<script type="text/javascript">
$(document).ready(function() {
$("#faq_search_input").keyup(function()
{
var faq_search_input = $(this).val();
var dataString = 'keyword='+ faq_search_input;
if(faq_search_input.length>1)
{
$.ajax({
type: "GET",
url: "listing.php",
data: dataString,
beforeSend: function() {
},
success: function(server_response)
{
$('#results').html(server_response).show();
$('span#faq_category_title').html(faq_search_input);
}
});
}return false;
});
});
</script>
...
...
<form method="get" action="">
<input name="query" type="text" id="faq_search_input" />
</form>
...
...
<td colspan="8">
<ul id="sortable">
<?php require_once('listing.php');?>
</ul>
</td>
...
...
Actually I think I’m loading the listing.php file twice now, as I see it. One time with the require_once and one time with my JavaScript. Can I improve this as well somehow?
So my question is: How can I get the ID to work with my javascript and could I restructer the code so I only load the listing.php once?
Please let me know if I am unclear, Im having a hard time explaining this.
Thanks a lot for any help
you should change
dataStringto