我的程序由两部分组成:
1)run.php 通过 JS 生成并共享 token ,这是我的 php 函数所需的。
$('.setURL').attr('href', 'save.php?token='+text);
<a class="setURL"><button>Save Settings</button></a>
2)code2.php通过$_GET从code.php接收 token 并启动函数。
$token = $_GET['token'];
为了扩展,我需要通过 cron 自动启动此过程,并寻找一种自动从 run.php 共享 token 到 save.php 的方法,而无需提交表单或单击按钮。
老实说,我尝试进行调查,但没有找到方法或线索。
最佳答案
I really don't understand, What you want to do actually, But the Answer for your question is,
无需单击按钮,即可通过ajax调用
以编程方式使用。
原版脚本
<script>
//ignores response
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "save.php?token="+text, true);
xhttp.send();
</script>
jQuery
<script>
$.get( "save.php?token="+text ); //ignores response
</script>
如果需要作为页面打开
<script>
window.open("save.php?token="+text, "_self"); //load in same tab
</script>
关于javascript - 自动将数据从 JavaScript 传递到 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58836315/