根据Mr.david请求更新问题。
Tester在下面的问题上创立了这个问题,即使我也是。
文本框1响应将转到==> 文本框2响应将转到==>
在textbox1和textbox2中输入的值和提交的按钮,ajax称为。
由于DB渲染速度慢,文本框2的值很快呈现。并且此输出显示在
中而不是
为什么会这样?
我有两个文本框和按钮, 当我们点击按钮时会触发ajax。
两个文本框值将转到ajax函数。
对于文本框1:call_ajax_val()将触发 对于文本框2:call_ajax_val2()将trgiger。
实际问题是, 当我点击按钮时,ajax将开始触发。 假设当我收到第二个文本框输入请求的响应时, 然后响应将如何转到call_ajax_val2函数。
因为在代码中,它看起来没有唯一标识符,所以这个响应是ajax处理。
下面的是两个ajax函数的一个公共代码。
> httpobj.onreadystatechange = function() { //Handler function for call
> back on state change.
> if(httpobj.readyState == 4) {
> document.getElementById('txt_group').innerHTML = httpobj.responseText;
> }
> }
当响应同时发生时会发生什么。响应将归功于哪个功能。
的index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
var xmlhttp;
function xmlhtpobj(){
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function call_ajax_val(){
var httpobj = xmlhtpobj();
var txt_get_me = document.getElementById("txt_get_me").value;
var url = "getreq.php?txt_get_me="+txt_get_me;
httpobj.open("GET", url, true);
httpobj.onreadystatechange = function() { //Handler function for call back on state change.
if(httpobj.readyState == 4) {
document.getElementById('txt_group').innerHTML = httpobj.responseText;
}
}
httpobj.send(null);
}
function call_ajax_val2(){
var httpobj = xmlhtpobj();
var txt_get_me2 = document.getElementById("txt_get_me2").value;
var url = "getreq.php?txt_get_me2="+txt_get_me2;
httpobj.open("GET", url, true);
httpobj.onreadystatechange = function() { //Handler function for call back on state change.
if(httpobj.readyState == 4) {
document.getElementById('txt_span').innerHTML = httpobj.responseText;
}
}
httpobj.send(null);
}
function commoncall(){
call_ajax_val1();
call_ajax_val2();
}
</script>
</body>
<form method="post">
<input type="text" id="txt_get_me" name="txt_get_me" />
<input type="text" id="txt_get_me2"/>
<span id="txt_span"></span>
<input type="button" onclick="return commoncall();"/>
</form>
<div id="txt_group"></div>
</html>
getreq.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("airport");
if (isset($_GET['txt_get_me1'])){
$selected_day = $_GET['txt_get_me1'];
$Query1 = "SELECT count( CallID ) , CallerGroup, CallDate, CallDay, OfficeNotes FROM tblcallerhistory WHERE CallDay = '$selected_day' GROUP BY CallDate";
$Resultset = mysql_query($Query1);
while($arr = mysql_fetch_array($Resultset)){
?>
<table border="1" >
<tr>
<td><?php print $arr[0]?><td>
<td><?php print $arr[1]?></td>
<td><?php print $arr[2]?></td>
<td><?php print $arr[3]?></td>
<td><?php print $arr[4]?></td>
</tr>
</table>
<?php
}
}
if (isset($_GET['txt_get_me2'])){
$UserID = $_GET['txt_get_me2'];
$query = "SELECT UserID,Username FROM tbluser WHERE UserID='$UserID'";
$resulset = mysql_query($query);
while($arrobj = mysql_fetch_array($resulset)){
?>
<table border="1" >
<tr>
<td><?php print $arrobj[0]?><td>
<td><?php print $arrobj[1]?><td>
<td><?php print $arrobj[2]?><td>
</tr>
</table>
<?php
}
}
?>
</body>
</html>