我的项目有问题。在我的站点中,我有一个带有单个按钮的页面 html,并且在 onclick() eventa js 函数调用 intro.js,通过 XmlHttpRequestObject 必须在许多 php 函数中执行许多调用,详细信息:
在 js 中我调用 scan() 函数
function scan() {
if (xmlHttp)
{
// try to connect to the server
try
{
// initiate reading the async.txt file from the server
xmlHttp.open("GET", "php/intro.php?P1=http://"+oStxt.value, true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
// change cursor to "busy" hourglass icon
document.body.style.cursor = "wait";
}
// display the error in case of failure
catch (e)
{
alert("Can't connect to server:\n" + e.toString());
// revert "busy" hourglass icon to normal cursor
document.body.style.cursor = "default";
}
}
}
在 handleRequestStatuschange 我有:
function handleRequestStateChange()
{
// obtain a reference to the <div> element on the page
// display the status of the request
if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4)
{
// revert "busy" hourglass icon to normal cursor
document.body.style.cursor = "default";
// read response only if HTTP status is "OK"
if (xmlHttp.status == 200)
{
try
{
// read the message from the server
response = xmlHttp.responseText;
// display the message
document.body.appendChild(oRtag);
oPch = document.getElementById("divRtag");
oOch = document.createTextNode(response);
oPch.appendChild(oOch);
}
catch(e)
{
// display error message
alert("Error reading the response: " + e.toString());
}
}
else
{
// display status message
alert("There was a problem retrieving the data:\n" +
xmlHttp.statusText);
// revert "busy" hourglass icon to normal cursor
document.body.style.cursor = "default";
}
}
}
它只适用于一个php调用,但我需要在intro.php(scan2.php,scan3.php,ecc ecc)之后在扫描函数中调用不同的php页面,并使用json_decode写入在div标签中返回的数组的单个数据我的html页面。使用ajax中的单个js函数调用不同的php页面并管理结果的最佳方法是什么?
提前感谢亚历山德罗