我是一个n00b试图通过在线教程学习jquery .ajax
。jquery`.ajax`不工作
我有以下的在我的本地的“客户”代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
$("#submit_btn").click(function(){
$.ajax({
type: "POST",
url: "response.php",
dataType: 'json',
data: { name: "John", location: "Boston" }
}).done(function(msg)
{
alert("Data Saved: " + msg);
});
});
});
</script>
</head>
<body>
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
</body>
</html>
而且我有以下我的“服务器”端文件的代码称为“response.php”:
<?php
if (isset($_POST))
{
$answer = $_POST;
echo json_encode($answer);
} else {
echo json_encode("no good");
}
?>
当我点击'发送'按钮时,我收到一条警告,提示“数据已保存:[对象对象]”。我试图通过使用click事件来显示通过`post'提交的数据。我希望警报显示'姓名:'约翰',位置:'波士顿''。
检查控制台的任何错误,它可能会抛出一个解析错误 – 2013-04-22 03:31:35
我不是一个PHP的人,还是我对'json_encode疑虑(“不良”)'给一个JSON O/p – 2013-04-22 03:32:04
是你的要求给予'不好'作为回应 – 2013-04-22 03:32:52