[英]How to send variables to php file with jquery/ajax and then echo the php to index (no alert)
我是这里的新手,我遇到了死胡同。
所以我创建了一个函数来在 php 中绘制日历。 而且我一直在使用 css 来设置日期的颜色等等。 该函数运行良好并使用 2 个输入变量,如下所示:
PHP 文件 (calendar.php):
<?php
function draw_calendar($month,$year)
{
// the code
}
echo draw_calendar($current_month,$current_year);
?>
我一直在尝试做的是使用 jquery/ajax(来自我的索引文件)将变量发布/获取到 calendar.php 以供 $current_month 和 $current_year 使用。 然后以某种方式将该函数回显到我的索引中。 对于我的生活,我无法做到这一点。 我只能找到如何返回简单的字符串并提醒他们注意我的索引。
我不确定你写了什么代码,但她是关于如何使用 ajax 发送你需要的变量的一般想法。
在您的索引文件上:
var month = "11"; //your month
var year = "2019"; //your year
$.ajax({
type: "POST",
url: "calendar.php",
data: {month: month, year: year},
dataType: "json",
success: function(response){
//if it is success
},
error: function(){
//if it results in error
}
});
在您的日历文件中:
$month = $_POST['month'];
$year = $_POST['year'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.