如何在$.ajaxjquery中从jasin检索数据

如何在$.ajaxjquery中从jasin检索数据,jquery,ajax,Jquery,Ajax,这个代码有什么问题 <html> <head> <script src="jquery.js"></script> <script> $(document).ready(function() { $("#butt").click(function() { var name=$("#male").val(); v

这个代码有什么问题

<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/>';
?>                               
您的响应不是您使用的json

dataType: "json",
在$.ajax中,您的响应是简单的html。请从代码中删除上述行或使用

dataType: "html",
试试这个

$.ajax({
    url:"email_ajax.php",
    data:"q="+samy, 
    type:"GET",
    success: function(res) {
        $("#result").html(res);  
    }
});

你的问题是什么?据我所知,它的格式是主要问题。你使用的是json_解码,但你没有向服务器发送json。您仅尝试将对象与字符串连接,这将导致类似于q=[object]。如果您真的想发送JSON,那么必须首先创建JSON。您可以通过JSON将对象转换为JSON。stringify.samy是一个对象,所以可能需要单独传递,或者转换为字符串+1对于问题编辑,做得好。如何在第二页转换字符串形式的此对象