gpt4 book ai didi

javascript - 在此ajax表单中将加载图标放在哪里请有人告诉我吗?

转载 作者:行者123 更新时间:2023-12-03 06:35:52 24 4
gpt4 key购买 nike

我的代码是这样的,我从教程网站上获取它,不记得在哪里,请告诉我在这个我不理解的巨大代码垃圾中将加载图标放在哪里。请通过 jsfiddle 或其他任何地方向我展示一个示例。

  <script language = "javascript" type = "text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!

try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e) {
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}

// Create a function that will receive data
// sent from the server and will update
// div section in the same page.

ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}

// Now get the value from user and pass it to
// server script.

var age = document.getElementById('age').value;
var wpm = document.getElementById('wpm').value;
var sex = document.getElementById('sex').value;
var queryString = "?age=" + age ;

queryString += "&wpm=" + wpm + "&sex=" + sex;
ajaxRequest.open("GET", "ajax-example.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>

<form name = 'myForm'>
Max Age: <input type = 'text' id = 'age' /> <br />
Max WPM: <input type = 'text' id = 'wpm' />
<br />

Sex: <select id = 'sex'>
<option value = "m">m</option>
<option value = "f">f</option>
</select>

<input type = 'button' onclick = 'ajaxFunction()' value = 'Query MySQL'/>

</form>

<div id = 'ajaxDiv'>Your result will display here</div>

最佳答案

首先,检查this了解有关就绪状态的更多信息。

我会在 ajaxRequest.open("GET", "ajax-example.php" + queryString, true); 之前添加一个加载内容并将其删除 if (xmlhttp.readyState==4 .

1.

因此,在您希望显示加载图标的位置添加 HTML: <span id="loading"></span>

2.

然后就在 ajaxRequest.open... 之前插入加载图像:

document.getElementById("loading").innerHTML = '<img src="loading.gif" />';

3.

里面if (xmlhttp.readyState == 4把:

document.getElementById("loading").innerHTML = '';

关于javascript - 在此ajax表单中将加载图标放在哪里请有人告诉我吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38214808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com