gpt4 book ai didi

javascript - 在 AJAX 函数执行时添加加载文本

转载 作者:行者123 更新时间:2023-12-03 09:42:58 26 4
gpt4 key购买 nike

我一直在尝试添加一个在 AJAX 函数执行时显示的加载文本,但我的所有尝试(包括使用 ajaxStart 和 ajaxStop 等)都没有成功。一直在工作。如有任何帮助,我们将不胜感激!

Here是相关脚本所在的网页(如果您想查看它的运行情况)。它的工作方式是,您输入一个网址,该函数将获取该网址的元标记。

同时,这里是相关的 HTML、Javascript 和 PHP:

HTML

<!DOCTYPE html>
<html>
<head>
<title>Keywords Grabber</title>

<script src="ajax.js"></script>
<script>
function display(content) {
document.getElementById("displaydiv").innerHTML = content;
}
window.onload = function () {
document.getElementById("btn1").onclick = function () {
var url = document.getElementById("txt1").value;
doAjax("metatags.php", "url=" + url, "display", "post", 0);
}
}
</script>


</head>
<body>
http://<input type="text" id="txt1" value="" />
<input type="button" id="btn1" value="Get Keywords" />
<h3>Keywords Received:</h3>
<div id="displaydiv"></div>



</body>
</html>

JavaScript

 function getXMLHttpRequest() {
try {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
return new ActiveXObject("Msml2.XMLHTTP");
}
}
catch(e) {
return new XMLHttpRequest();
}
}
function doAjax(url, query, callback, reqtype, getxml) {
var myreq = getXMLHttpRequest();
myreq.onreadystatechange = function () {
if (myreq.readyState == 4) {
if (myreq.status == 200) {
var item = myreq.responseText;
if (getxml == 1) item = myreq.responseXML;
eval(callback + '(item)');
}
}
}
if (reqtype.toUpperCase() == "POST") {
requestPOST(url, query, myreq);
} else {
requestGET(url, query, myreq);
}
}

function requestGET(url, query, req) {
var myRandom = parseInt(Math.random()*99999999);
if (query == '') {
var callUrl = url + '?rand=' + myRandom;
} else {
var callUrl = url + '?' + query + '&rand=' + myRandom;
}
req.open("GET", callUrl, true);
req.send(null);
}
function requestPOST(url, query, req) {
req.open("POST", url, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(query);
}

PHP

    <?php
$tags = @get_meta_tags('http://'.$_REQUEST['url']);
$result = $tags['keywords'];
if(strlen($result) > 0) {
echo $result;
} else {
echo "No keywords metatag is available.";
}
?>

最佳答案

类似这样的事情

 <div id="loading" style="display:none;">loading</div>

Javascript

 $('#loading').css('display', 'block');
$.post(url, {}, function(data){
$('#loading').css('display', 'none');
});

关于javascript - 在 AJAX 函数执行时添加加载文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31131318/

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