時,我有一種形式,像這樣:Ajax錯誤日期不確定射擊
<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選擇器的問題,但如果是這樣,它會是什麼?
我認爲你可以得到的JavaScript未定義因此檢查值dateStart.val()和dateEnd.val() – Hkachhia 2013-03-19 04:39:38