PHP和Jquery的json

goo*_*ing 3 php jquery json types

我的html文件:

    <script>
    $(document).ready(function() {  
        $.ajax({
            type: "POST",
            url: "search.php",
            data: "id=1",
            datatype: "json",
            success: function(msg){
                $('.result1').html(msg["name"]);
            }
        });  
    })
    </script>   

    <span class="result1"></span>
Run Code Online (Sandbox Code Playgroud)

我的php文件:

    <?
    $a["name"] = 'john';
    echo json_encode($a);
    ?>
Run Code Online (Sandbox Code Playgroud)

为什么名称John没有出现在类result1中?为什么?请帮帮我,我疯了.

编辑:现在可以获得赏金吗?

Tom*_*igh 5

dataType参数有一个大写T.如果你纠正这个,它就有效.

目前它(默认情况下)试图根据mime类型猜测响应格式,所以可能默认为html - 在firebug中调试你可以看到msg成功回调的参数是一个包含JSON的字符串.