[英]GetXmlHttpObject AJAX call to a php file
I am trying to call a php file using GetXmlHttpObject object and having some luck, but seem to have problem with the URL variable. 我正在尝试使用GetXmlHttpObject对象调用php文件,但有些运气,但是URL变量似乎有问题。
Is there something I have to do with the URL string differently? URL字符串与我有什么不同吗?
Here is the relevant code: 以下是相关代码:
remoteCounter('marks');//invoking function
document.write("<div id=\"marks\"></div>");//destination div
function GetXmlHttpObject () {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari, IE 7+
xmlHttp = new XMLHttpRequest();
} catch (e) {
// Internet Explorer - old IE - prior to version 7
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function remoteCounter(param){
counterObj = GetXmlHttpObject();
var url="HTTP://dnsname/directory/view.php?" + param;
alert(url + " " + counterObj);
counterObj.open("GET", url , true);
counterObj.onreadystatechange=updateCounter;
counterObj.send(null);
}
function updateCounter(){
//alert('updateCounter');
if (counterObj.readyState == 4 || counterObj.readyState == "complete"){
document.getElementById("marks").innerHTML=counterObj.responseText;
}
}
I can replace the counterObj.responseText variable in document.getElementById("marks").innerHTML=counterObj.responseText; 我可以替换document.getElementById(“ marks”)。innerHTML = counterObj.responseText;中的counterObj.responseText变量。
and see the test string correctly in the source document, so I know the html and jscript source is not the problem. 并在源文档中正确看到测试字符串,所以我知道html和jscript源不是问题。
I have commented out code in the view.php file to just echo a simple string, but that is not showing either - which again makes me think the problem is in the request to the file, not in the file, not in the source. 我已经在view.php文件中注释掉了代码,只是回显了一个简单的字符串,但这也没有显示-这再次使我认为问题出在文件请求中,而不是文件中,而不是源中。
Actual server name and directory have been replaced by dnsname/directory for this post. 实际服务器名称和目录已被dnsname / directory代替。 Including alert for debugging.
包括调试警报。
thank you for assistance. 谢谢您的协助。
Replace order of two first lines: 替换前两行的顺序:
document.write("<div id=\"marks\"></div>"); //destination div
remoteCounter('marks'); //invoking function
It's necesary declarate div tag with id "marks" first. 首先需要声明ID为“ marks”的 div标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.