【发布时间】:2014-05-11 20:41:48
【问题描述】:
-
下面的函数/ajax 请求拒绝工作/'post',我不知道为什么。
-
我假设 PHP 脚本从我的 Ajax 请求中接收到的任何数据变量都应引用为
$_POST['sday']和$_POST['sdate']? -
PS 成功函数应该如何处理来自我的 PHP 脚本的 JSON 编码响应?
我的代码:
<html>
<head>
<title></title>
</head>
<body>
<h1>Welcome to Richmond nursing app, you have successfully logged in!</h1>
<hr>
<form id="idForm" name="idForm">
<input type="text" size="8" id="date" name="date"><br>
<input type="hidden" size="8" id="reversedate" name="reversedate"><br>
<input type="hidden" size="1" id="dow" name="dow"><br>
<input type="submit" id="submitbutton" name="submitbutton">
</form>
<div id="report" name="report">
</div>
<br><br><br>
<br>
<br>
<p id="p1">x</p>
<br>
<a href="logout.php">log out</a>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
<script>
$('#submitbutton').click(function(){
var fulldate=$('#date').datepicker('getDate');
var date=fulldate.getDate();
var day=fulldate.getDay();
var month=fulldate.getMonth()+1;
var year=fulldate.getFullYear();
if (month<10)
{month="0"+month};
if(date<10)
{date="0"+date};
var selecteddate=year+"-"+month+"-"+date;
var url = "fetchsimple.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: {sdate: selecteddate, sday:day}, // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript ajax post