这是在code我有。我试图插入一个图像显示,Ajax是加载,但我不能得到这个权利;我尝试了很多可能的方法,但它只是不工作。在做什么有什么建议?
ajaxRequest.onreadystatechange =功能(){
如果(ajaxRequest.readyState == 4){
变种ajaxDisplay =的document.getElementById('main_result');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
$(#main_result)空()的HTML。('< IMG SRC =loading.gif/>');
。VAR类=的document.getElementById('类')值;
。VAR品牌=的document.getElementById(品牌)的价值;
VAR项目=的document.getElementById('项目')值。
VAR查询字符串=&放大器;类=+分类+&放大器;品牌=+品牌+&放大器;项目=+项目;
ajaxRequest.open(GET,?main_search_special.php节=特殊+查询字符串,真实);
ajaxRequest.send(空);
解决方案
只是将图像添加到您的显示区域,你发送请求之前。请求完成后的结果将覆盖它。
...
变种ajaxDisplay =的document.getElementById(main_result);
ajaxDisplay.innerHTML =&其中; IMG SRC =loading.gif'/>中
ajaxRequest.send(空);
This is the code I have. I'm trying to insert a image to show that ajax is loading but I just can't get this right; I tried a lot of possible ways but it just isn't working. Any suggestions on what to do?
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('main_result');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
$("#main_result").empty().html('<img src="loading.gif" />');
var category = document.getElementById('category').value;
var brand = document.getElementById('brand').value;
var item = document.getElementById('item').value;
var queryString = "&category=" + category + "&brand="+ brand +"&item="+ item;
ajaxRequest.open("GET", "main_search_special.php?section=special" + queryString, true);
ajaxRequest.send(null);
解决方案
Just add the image to your display area before you send the request. The results will overwrite it when the request completes.
...
var ajaxDisplay = document.getElementById("main_result");
ajaxDisplay.innerHTML = "<img src='loading.gif' />"
ajaxRequest.send(null);