我想使用 jQuery 从 URL 获取 JSON:
$.getJSON('http://example.com/file.php', function(data) {
//data
});
示例 JSON:{ "url":"http://example.com/execute.php"}
然后我想在后台执行我们从 JSON 文件获得的 URL(客户端,而不告诉用户)。
并且每秒重复整个过程!每秒获取 JSON 并在后台执行等等..
最佳答案
function callPhpFile() {
$.ajax({
file: "http://yoururl.com/executethis/script.php"
method: 'POST',
success: function(data) {
setTimeout(function() { callPhpFile() }, 1000);
}});
}
setTimeout(function() { callPhpFile() }, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Then I want to execute the URL in background (client side and without telling to user) which we have got from JSON file.
您不需要 AJAX 来进行响应,您也可以将其用作请求。这只会在您每次调用 PHP 页面时运行它。在成功监听器中,您可以执行任何操作,或者实现 setInterval()
来重复该过程
关于JavaScript:从 JSON 文件中获取 URL 并在后台执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46302356/