admin 管理员组文章数量: 1086019
How should I do this?
function(id,id2){
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
First Request:
xmlhttp.open("GET", ".php?id="+id, true); xmlhttp.send();
Second Request:
xmlhttp.open("GET", ".php?id2="+id2, true); xmlhttp.send();
}
Because in this way doesn't works.
I want to make it in plain javascript, so please do not post answers with jQuery or any library etc.
Thanks
How should I do this?
function(id,id2){
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
First Request:
xmlhttp.open("GET", "http://example./ajax.php?id="+id, true); xmlhttp.send();
Second Request:
xmlhttp.open("GET", "http://example./ajax2.php?id2="+id2, true); xmlhttp.send();
}
Because in this way doesn't works.
I want to make it in plain javascript, so please do not post answers with jQuery or any library etc.
Thanks
Share Improve this question edited Aug 29, 2010 at 6:48 Adam Halasz asked Aug 29, 2010 at 6:33 Adam HalaszAdam Halasz 58.4k67 gold badges153 silver badges216 bronze badges 2- Use JQuery Ajax. it is simple to use. You will find solution for this. – Muneer Commented Aug 29, 2010 at 6:43
- Thanks for your answer, but I want to make it in plain Javascript :) – Adam Halasz Commented Aug 29, 2010 at 6:46
2 Answers
Reset to default 8It should work if you create a new xmlhttp object. Currently you are attempting to reuse the same object, which is already performing a query so it will not work.
if you are looking for classic javascript style you can use as the following. But use jQuery as it's simple and prehensive. The one thing to be noted is that the "xmlhr" should be in method (callAjax) scope.
function callAjax(url) {
var xmlhr;
if (window.XMLHttpRequest) {
xmlhr = new XMLHttpRequest();
} else {
xmlhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhr.onreadystatechange = function () {
if (xmlhr.readyState == 4 && xmlhr.status == 200) {
alert(xmlhr.responseText);
}
}
xmlhr.open("GET", url, true);
xmlhr.send();
}
function myFunction(id1, id2) {
callAjax("http://example./ajax2.php?id2=" + id1);
callAjax("http://example./ajax2.php?id2=" + id2);
}
本文标签: javascriptAJAX How to use TWO xmlHttpRequest in parallel in ONE functionStack Overflow
版权声明:本文标题:javascript - AJAX: How to use TWO xmlHttpRequest in parallel in ONE function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744012119a2518348.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论