[英]pass vars from javascript ajax to php
I just search around web without found solution : 我只是在网上搜索而未找到解决方案:
I have a script where I have this code to reload a query resident in ftp_logs_table2.php
without manually refresh the script. 我有一个脚本,其中有这段代码可以重新加载驻留在
ftp_logs_table2.php
的查询,而无需手动刷新脚本。
<div id="show"></div>
<script type="text/javascript">
$(document).ready(function() {
setInterval(function() {
$('#show').load('ftp_logs_table2.php')
}, 1000);
});
</script>
the problem is that I have to pass 2 vars to the query on ftp_logs_table2.php
and I don't know howto : thanks 问题是我必须将2个变量传递给
ftp_logs_table2.php
上的查询, ftp_logs_table2.php
我不知道该如何做:谢谢
You need to set up for jQuery ajax function like this. 您需要像这样为jQuery ajax函数进行设置。 To pass parameters to the server, user the
data
attribute: 要将参数传递给服务器,请使用
data
属性:
<div id="show"></div>
<script type="text/javascript">
$(document).ready(function() {
setInterval(function () {
$.ajax({
url: 'ftp_logs_table2.php',
data: { var1: 'data', var2: 'data' },
method: 'POST',
success: function(data) {
$('#show').html(data);
}
})
}, 1000);
});
</script>
That is a very basic example. 这是一个非常基本的例子。 There is great jQuery documentation and examples, as always http://api.jquery.com/jquery.ajax/
一如既往http://api.jquery.com/jquery.ajax/ ,有很多jQuery文档和示例
It looks like you're already using jQuery, so you can use the $.ajax
function from that library. 看起来您已经在使用jQuery,因此可以使用该库中的
$.ajax
函数。
With passing data to your PHP file your code will look something like the following; 通过将数据传递到PHP文件,您的代码将如下所示;
$.ajax({
method: "POST",
url: "ftp_logs_table2.php",
data: { this: "that", foo: "bar" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
The docs for it can be found here: http://api.jquery.com/jquery.ajax/ 可以在这里找到它的文档: http : //api.jquery.com/jquery.ajax/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.