ajax错误日期在触发时未定义

Dav*_*d G 0 php ajax undefined

我有一个这样的表格:

<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>
Run Code Online (Sandbox Code Playgroud)

还有一些像这样的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;
    }); 
}); 
Run Code Online (Sandbox Code Playgroud)

哪个发送到这个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);
Run Code Online (Sandbox Code Playgroud)

我没有包括剩下的功能.

然而,我遇到的问题是检查(因为查询不起作用),我的post方法中的dateStart和dateEnd都显示为"未定义".

我不知道为什么这么模糊.我错过了一些明显的东西吗 我怀疑它必须是我的jquery选择器的一个问题,但如果是这样,它会是什么?

Edw*_*lex 5

你必须使用这样的选择器,

var dateStart = $('input[name="dateStart"]');
var dateEnd = $('input[name="dateEnd"]');
Run Code Online (Sandbox Code Playgroud)