执行ajax返回Error: No conversion from text to json错误,什么原因,如何解决?

解决方案 »

  1.   

    貌似返回的东西不能转换成json的样子 你把返回的东西发下看看
      

  2.   


    Error: No conversion from text to json
    OK
    {"success":"yes"}
    这样输出的
    error: function(xhr, ajaxOptions, thrownError) {
       alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    }
      

  3.   

    ajax代码 $.ajax({
    url: 'http://localhost/index.php',
    type: 'post',
    data: $('#div :input'),
    dataType: "json",
    success: function(data) {
    alert(data);
    },
    error: function(xhr, ajaxOptions, thrownError) {
    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    }
    });
    php代码:if($_SERVER['REQUEST_METHOD'] == 'POST') {    $json = array();
        if(isset($_POST['title'])){
           $json['success'] = 'yes';
        } else {
            $json['error'] = 'no';
        }
        echo json_encode($json);
    }
      

  4.   

    - -!随手打成等号了。
    contentType: "json"