我需要一些帮助。我正在向服务器发送简单的请求,我期望的返回是 JSON 作为数据类型。但是当我检查开发工具控制台日志时,我得到“parsererror SyntaxError {}”和“parsererror”。
我怎样才能做到这一点?下面是代码。
jQuery
$(':submit').live('click', function() {
    $.ajax({
            type : 'post',        
            url: 'testJSON.php',
            beforeSend:console.log('sending...'),
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            success: function(data){
                console.log(data.status);
                // do magic
                },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log(textStatus, errorThrown);
                },
            complete: function(XMLHttpRequest, status) {
                console.log(status);
                }
        });
    return false;
    });
这是 testJSON.php
<?php
$data = array(
    "status" => 1,
    "firstname" => "foo",
    "lastname" => "bar",
);
header('Content-type: application/json; charset=utf-8" ');
echo json_encode($data);
exit();
?>
仅供参考,我使用最新版本的 WAMP。非常感谢任何帮助。