0

有没有办法使用现有的ajax代码传递下面表单的“日期”输入值?我意识到目前我正在传递“peter”和“Sheffield”,但想将其切换为表单中输入的值:

<!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",
      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

1 回答 1

2

你可以得到日期$('input[name="date"]').val()

因此,您的数据值将如下所示:

data: "name=Peter&location=Sheffield&date=" + $('input[name="date"]').val(),
于 2013-01-03T22:54:46.457 回答