在我的PHP中,我正在解析Json链接,我正在搜索脚本,因为脚本会显示加载器直到解析完成。 例如:
<?php
echo " spinner here" ;
sleep(5);//lets say this is parsing json script
?>
我尝试了很多东西而且没有用,请帮忙。
答案 0 :(得分:1)
如果你想用Ajax做,这就是它的工作原理:HTML代码有一个按钮,当点击它启动“spinner”并调用PHP解析代码时,当PHP解析代码完成时,它返回到Ajax和spinner停止了:
<强> spinner.html 强>
<html>
<head>
<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>
<script type="text/javascript">
function myAjax ()
{ $("#my_div").html( "Wait while parsing..." ); // START SPINNER.
$.ajax( { type : 'POST',
url : 'spinner.php', // CALL PHP CODE.
success : function ( result )
{ $("#my_div").html( result ); // STOP SPINNER.
},
error : function ( xhr )
{ alert( "error" );
}
}
);
}
</script>
</head>
<body>
<button onclick="myAjax()">Parse JSON links</button>
<div id="my_div"></div> <!-- YOUR SPINNER HERE -->
</body>
</html>
<强> spinner.php 强>
<?php
sleep( 5 );
echo "Parsing finished!";
?>
只需创建两个具有给定名称的文件,复制粘贴这些代码并运行!
答案 1 :(得分:0)