我有这 4 个页面并且工作正常,但是现在我需要将在(index.php)的输入字段中键入的“单词”发送到另一个页面(pag2.php),同时它发送到(pag1.php)在 (script.php) 使用这个 javascript 代码。
索引.php
<form method="post">
<input type="text" name="word" id="word" onkeyup="getSugest(this.value);">
</form>
<div class='search'><img ..... searching.gif></div>
<div id="sugest">
<div id="resultIndex"></div>
<div id="buttonsIndex">
<ul>
<?
for($i=1; $i<=page; $i++;){
echo "<li id='".$i."'>".$i."</li>";
}
?>
<ul>
</div>
</div>
脚本.js
function getSugest(value){
if(value != ""){
if (callPage1(value) || callPage2(value)) {
var data1 = callPage1(value);
var data2 = callPage2(value);
//var combinedData = combine as data1 and data2 as you want
$("#sugest").html(combinedData);
} else {
$("#sugest").html("Theres nothing in DB!");
}
}
}
function callPage1(value) {
$.post("pag1.php",{word:value},function(data){
if(data != ""){
return data;
}
else{
false;
}
});
}
function callPage2(value) {
$.post("pag2.php",{word:value},function(data){
if(data != ""){
return data;
}
else{
false;
}
});
}
$(document).ready(function(){
function showLoader(){
$('.search').fadeIn(200);
}
function hideLoader(){
$('.search').fadeOut(200);
};
$("#buttonIndex li").click(function(){
showLoader();
$("#buttonIndex li").css({'background-color' : ''});
$(this).css({'background-color' : '#D8543A'});
$("#resultIndex").load("pag1.php?page=" + this.id, hideLoader);
return false;
});
$("#buttonCar li").click(function(){
showLoader();
$("#buttonCar li").css({'background-color' : ''});
$(this).css({'background-color' : '#D8543A'});
$("#resultCar").load("pag2.php?page=" + this.id, hideLoader);
return false;
});
$("#1").css({'background-color' : '#D8543A'});
showLoader();
$("#resultIndex").load("pag1.php?page=1", hideLoader);
$("#resultCar").load("pag2.php?page=1", hideLoader);
});
页面1.php
$word = mysql_real_escape_string(addslashes($_POST['word']));
echo "Word is: ".$word;
//here is the php and mysql querys to return the result
页面2.php
$word = mysql_real_escape_string(addslashes($_POST['word']));
echo "Word is: ".$word;
//here is the php and mysql querys to return the result
我很感激任何帮助。