私はそのような形をしています:
<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セレクターに問題があるのではないかと思いますが、もしそうなら、それは何でしょうか?