此代码有什么问题?
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function() {
$("#butt").click(function() {
var name=$("#male").val();
var age =$("#age").val();
var edu=$("#education").val();
var samy ={
"name":name,
"age":age,
"edu":edu
};
$.ajax( {
url:"email_ajax.php",
data:"q="+samy,
type:"GET",
dataType: "json",
success: function(res) {
res = $.parseJSON(res);
$("#result").html(res);
}
});
});
});
</script>
</head>
<body>
<label for="male">Male</label>
<input type="text" name="male" id="male"><br/>
<label for="Education">Education</label>
<input type="text" name="education" id="education"><br/>
<label for="age">Age</label>
<input type="text" name="age" id="age"><br/>
<input type="button" id="butt" name="butt">
<div id="result"></div>
</body>
</html>
在下一页
<?php
$da=$_GET['q'];
$data=json_decode($da);
$x=$data['name'];
$y=$data['age'];
$z=$data['edu'];
echo '<h4>'.$x.'</h4><br/>';
echo '<h4>'.$y.'</h4><br/>';
echo '<h4>'.$z.'</h4><br/>';
?>
答案 0 :(得分:1)
您使用的response
不是json
dataType: "json",
在$.ajax()
中,您的response
很简单html
从您的代码中移除上述行或使用
dataType: "html",
试试这个,
$.ajax({
url:"email_ajax.php",
data:"q="+samy,
type:"GET",
success: function(res) {
$("#result").html(res);
}
});