亲爱的人我正在使用AJAX和PHP
执行日历功能$showmonth = $_POST['showmonth'];
$showyear = $_POST['showyear'];
$pre_days = date ('w', mktime(0,0,0, $showmonth, 1, $showyear));
$post_days = (6 - (date('w', mktime(0, 0, 0, $showmonth, $day_count, $showyear))));
我不断收到错误消息:
注意:未定义的索引:第2行的C:\ xampp \ htdocs \ calendar_start.php中的showmonth
注意:未定义的索引:第3行的C:\ xampp \ htdocs \ calendar_start.php中的showyear
警告:cal_days_in_month()期望参数2为long,第8行的C:\ xampp \ htdocs \ calendar_start.php中给出字符串
警告:mktime()期望参数4为long,第9行的C:\ xampp \ htdocs \ calendar_start.php中给出字符串
警告:mktime()期望参数4为long,第10行的C:\ xampp \ htdocs \ calendar_start.php中给出字符串
我认为这与我的AJAX java脚本有关,但我不知道AJAX代码还有哪些部分,但我认为这是困扰我的部分
function next_month() {
var nextmonth = showmonth + 1;
if(nextmonth >12) {
nextmonth = 1;
showyear = showyear + 1;
}
showmonth = nextmonth;
var hr = new XMLHttpRequest();
var url = "calendar_start.php";
var vars = "showmonth="+showmonth+"&showyear="+showyear;
hr.open("POST",url,true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("showCalendar").innerHML = return_data;
}
}
hr.send(vars);
document.getElementById("showCalendar").innerHTML = "processing...";
}
</script>
这也许也是问题所在:
function initialCalendar() {
var hr = new XMLHttpRequest();
var url = "calendar_start.php";
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var year = currentTime.getFullYear();
showmonth = month;
showyear = year;
var vars = "showmonth="+showmonth+"&showyear="+showyear;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("showCalendar").innerHML = return_data;
}
}
hr.send(vars);
document.getElementById("showCalendar").innerHTML = "processing...";
}
答案 0 :(得分:2)
花了我5个小时后,我发现了这个: http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
在这里你可以发现你只需要2行:
hr.setRequestHeader("Content-length", vars.length);
hr.setRequestHeader("Connection", "close");
答案 1 :(得分:1)
如果你在javascript中更改了这个???
var url = "calendar_start.php";
var vars = "showmonth="+showmonth+"&showyear="+showyear;
var final_url = url+"?"+vars;
alert(final_url); //this line should a message with the url, post it please.
hr.open("GET",final,true);
这应该有效。
PS:你通过get params传递你的url所以在你的php文件中你应该像
那样收到它们$showmonth = $_GET['showmonth']; //I change POST by GET
$showyear = $_GET['showyear']; //DONT forget to chenge this in your php file
Saludos;)
答案 2 :(得分:1)
您是否使用相同的方法(POST / GET)发送和接收参数......? 如果不是这样..可能会给出未定义的索引错误... 即如果您使用GET发送参数并使用POST接收参数,反之亦然..