0

嗨,我将如何从下面的代码中在 PHP 文件中回显表单输入“日期”。( data: "name=Peter&location=Sheffield" + $('input[name="date"]').val(),)

目前我有echo "todays date ".$_POST['date']."<br>";,但它似乎不起作用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript"
    src=http://code.jquery.com/jquery-latest.js>    
</script>
<script type="text/javascript">
// This functions starts the ajax to show the output from post.php
function StartAjax(ResultsId){
    $.ajax({
      type: "POST",
      url: "postTest.php",
      cache: false,
      data: "name=Peter&location=Sheffield" + $('input[name="date"]').val(),
      success: function(html, status){
        $("#"+ResultsId).append(html);
        $('#status').append(status);
      } 
    });
}
</script>
</head>
<body>
<h1> Run Club</h1>
testing
<form>
date: <input type="text" name="date"><br>
</form>
<a href="#" onclick="StartAjax('ResultsId');">Click Here to see updates from postTest.php</a>
<div id="ResultsId"></div>
<div id="status"></div>
</body>
</html>
4

2 回答 2

1

您必须在查询字符串中输入日期键

data: "name=Peter&location=Sheffield&date=" + $('input[name="date"]').val(),

或者,您应该将对象传递给数据,以便 jQuery 为您格式化查询字符串。

data: {name: "Peter", location: "Sheffield", date: $('input[name="date"]').val()},
于 2013-01-03T23:30:11.983 回答
-1
function StartAjax(ResultsId){
var date = document.getElementsByName("date").val();
    $.ajax({
      type: "POST",
      url: "postTest.php",
      cache: false,
      data: "name=Peter&location=Sheffield&date=" + date,
      success: function(html, status){
        $("#"+ResultsId).append(html);
        $('#status').append(status);
      } 
    });
}
于 2013-01-03T23:32:46.900 回答