我有一个像这样的表格:
<form method="post" action="functions/updateWeek.php">
<label for="dateStart">View From</label>
<input type="date" name="dateStart" required>
<label for="dateEnd">Until</label>
<input type="date" name="dateEnd" required>
<input type="submit" id="submitWeek" value="Go"/>
</form>
还有一些像这样的javascript:
$(document).ready(function() {
//if submit button is clicked
$('#submitWeek').click(function () {
//Get the data from the field
var dateStart = $('date[name=dateStart]');
var dateEnd = $('date[name=dateEnd]');
//organize the data properly
var data = 'dateStart=' + dateStart.val() + '&dateEnd=' + dateEnd.val();
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "functions/updateWeek.php",
//GET method is used
type: "POST",
//pass the data
data: data,
//Do not cache the page
cache: false,
success: function() {
alert("done");
}
});
//cancel the submit button default behaviours
return false;
});
});
发送到这个 php 文件:
//Start sessions
session_start();
//include config file
include_once 'config.php';
include_once 'accountFunctions.php';
//get start date from form
$dateStart = $_POST['dateStart'];
//get end date from form
$dateEnd = $_POST['dateEnd'];
//collect the start week
$startWeek = getStartWeek($dateStart);
//collect the end week
$endWeek = getEndWeek($dateEnd);
我没有包括其余的功能。
然而,我遇到的问题是经过检查(因为查询不起作用),我的 post 方法中的 dateStart 和 dateEnd 似乎都是“未定义的”。
至于为什么,我一无所知。我错过了一些明显的东西吗?我怀疑这一定是我的 jquery 选择器的问题,但如果是这样,它可能是什么?