-3

这段代码有什么问题?

<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/>';
?>                               
4

1 回答 1

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);  
    }
});
于 2013-08-25T14:38:21.650 回答