请看一下这个 PHP 脚本 (sendingpage.php):
$i=1;
While(whatever){
echo "<input id='ref".$i."' type='hidden' value='".$variable."' />";
echo "<input id='ref2".$i."' type='hidden' value='".$variable2."' />";
$i++;
}
现在,我想要做的是使用 JQUERY AJAX 方法将所有值传递到另一个 php 页面 (receivingpage.php),并在 receivepage.php 中处理接收到的数据后,将结果加载到我的 movingpage.php 中。请注意,我不知道此脚本将生成多少个 cicle,也不知道每个 cicle 中 $variable 和 $variable2 将保存什么值。
我认为我可以完成所有最终的加载操作,但我遇到的麻烦是使用 AJAX/JQUERY 将所有值从sending.php 传递到receive.php
我希望你们能为我提供一些线索。我将不胜感激。
最佳答案
如果这是在 <form>
内那么你可以使用serialize
函数将其作为 ajax 调用中的数据传递。
喜欢
$.ajax({
type :'POST',
data:$('#formId').serialize();
...so on
})
还建议将类型设置为 post,因为它将允许您将其作为 post 请求发送,并将发送请求中的所有表单字段。
关于jquery - 如何通过JQUERY/AJAX传递不确定数量的php变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14395346/