不适用于Firefox和Safari [英] Not working in Firefox and Safari
本文介绍了不适用于Firefox和Safari的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好
我有以下代码:
function addItem(str){
if (str == ){
document .getElementById( txtHint)。innerHTML = 跨度>;
return ;
}
if ( window .XMLHttpRequest){
// IE7 +,Firefox,Chrome,Opera,Safari的代码
xmlhttp = new XMLHttpRequest();
} 其他 { // IE6的代码,IE5
xmlhttp = new ActiveXObject( Microsoft.XMLHTTP跨度>);
}
xmlhttp.onreadystatechange = function (){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ){
document .getElementById( txtHint ).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open( GET, checkinout-actions / add-more-items-code.php?q = + str,< span class =code-keyword> true );
xmlhttp.send();
window 。 location .reload();
}
它适用于谷歌浏览器,但标题中提到的其他浏览器无效。
能帮帮我吗
非常感谢你!
解决方案
试试这个:
< pre lang =javascript> var request = new XMLHttpRequest();
request.open(' GET', checkinout-actions / add-more-items-code.php?q = + str);
request.onreadystatechange = function (){
if ( request.readyState == 1 ){ return }
else if (request.readyState == 4 ){
< span class =code-keyword> if (request.status< 400 ){
// 在这里做你的东西
document .getElementById( txtHint)。innerHTML = request.responseText;
}
else if (错误!= null )
错误(请求);
}
};
request.send();
Hi
I have the following codes:
function addItem(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","checkinout-actions/add-more-items-code.php?q="+str,true);
xmlhttp.send();
window.location.reload();
}
It is working in Google Chrome but the other browsers mentioned in the title it is not working.
Can you please help me out.
Thank you so much!
解决方案
Try this :
var request = new XMLHttpRequest(); request.open('GET', "checkinout-actions/add-more-items-code.php?q="+str); request.onreadystatechange = function () { if (request.readyState == 1) { return } else if (request.readyState == 4) { if (request.status < 400) { // do your stuff here document.getElementById("txtHint").innerHTML=request.responseText; } else if (error != null) error(request); } }; request.send();
这篇关于不适用于Firefox和Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文