jquery发布回调问题

时间:2010-10-21 08:37:46

标签: jquery

我无法获得任何回调数据:

    <script type="text/javascript">
jQuery(function(){
jQuery("#JqPostForm").submit(function(){
        jQuery.post("index.php?option=comp&task=sendemail", jQuery("#JqPostForm").serialize(),

        function(data){
        alert('ok');
            if(data.email_check == 'invalid'){

                    jQuery("#message_post").html("<div class='errorMessage'>Sorry " + data.name + ", " + data.email + " is NOT a valid e-mail address. Try again.</div>");
            } else {
                jQuery("#message_post").html("<div class='successMessage'>" + data.email + " is a valid e-mail address. Thank you, " + data.name + ".</div>");
                }
        }, "json");

        return false;

});
});
</script>

php函数中的echo是:echo json_encode($return_arr);,即:{"email_check":"invalid","name":null,"email":null}

但无法让它正常工作我正在开发localhost和firefox

1 个答案:

答案 0 :(得分:0)

确保服务器发送适当的内容类型:

header('Content-type: application/json');