开发者

Different errors with different browsers in ajax call

开发者 https://www.devze.com 2023-03-20 19:10 出处:网络
What is the reason for this error? How do I fix? error with Google Chrome : An error has occured: [object Object] parsererror SyntaxError:

What is the reason for this error? How do I fix? error with Google Chrome :

An error has occured: [object Object] parsererror SyntaxError: Unexpected token ILLEGAL

error with opera:

An error has occured: [object Object] parsererror SyntaxError: JSON.parse: Unable to parse value:

error with ie9:

An error has occured:开发者_Python百科 [object Object] parsererror SyntaxError: Invalid character

and ...

js code:

$('#hotel').keypress(function () {
    var dataObj = $(this).closest('form').serializeArray();
    $.ajax({
        url: 'http://localhost/mehdi/admin/tour/search_hotel',
        data: dataObj,
        dataType: 'json',
        success: function (data) {
            $("#suggestion_tab").html('');
            $.each(data.suggestions, function (a, b) {
                $("#suggestion_tab").append('<li>' + data.b + '</li>');
            });
            // Display the results
            ///alert(data);
        },
        "error": function (x, y, z) {
            // callback to run if an error occurs
            alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
        }
        });
    });

php:(CI_Controller)

function search_hotel(){
    $searchterm = $this->input->post('search_hotel');
    $result = $this->model_tour->search_hotel($searchterm);
    while($row = mysql_fetch_assoc($result))
    {
        $output[] = $row;
    }
    echo json_encode(array('suggestions' => $output));
}

CI_Model

function search_hotel($searchterm)
{
    return mysql_query("select * from hotel_submits where name LIKE '".$searchterm."'");
}


Your JSON contains invalid syntax.
You need to look at the actual JSON and fix the error.


Also make sure, that your response is in UTF.


This can happen due to session timeout.


Try using http://jsonlint.com/ to see if the JSON packet is valid. It looks to me like you need to json_encode every one of the rows from the database, and then add those encoded packets to another JSON array?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号