小编Bru*_*ler的帖子

jQuery,Ajax,JSON,PHP和parsererror

我想一个形式发送给使用PHP $.ajax的jQuery.我将整个事件作为JSON发送,但是,当我尝试获得响应时,我得到'parsererror'.我究竟做错了什么?

jQuery片段:

$("form").submit(function(){
    $.ajax({type: "POST",
        url: "inscrever_curso.php",
        data: {cpf : $("input#cpf").val(),nome : $("input#nome").val()},
        dataType: "json",
        success: function(data){
            alert("sucesso: "+data.msg);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            alert ("erro: "+textStatus);
        }
    });
    return false;
});
Run Code Online (Sandbox Code Playgroud)

PHP:

<?php
    $return[msg]="Testing, testing.";
    echo json_encode($return);
?>
Run Code Online (Sandbox Code Playgroud)

php ajax jquery json

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

ajax ×1

jquery ×1

json ×1

php ×1