0

当我尝试解析我的 JSON 时,我什至不知道为什么会出现此错误:

Uncaught SyntaxError: Unexpected token < login.js:7
$.ajax.success login.js:7
l jquery2.0.js:4
c.fireWith jquery2.0.js:4
k jquery2.0.js:6
(anonymous function)

我的 jquery 脚本在这里:

$(".input-submit").click(function(){
    $.ajax({
        url: "./index.php?action=login",
        type: "POST",
        data: {login:$("#login").val(),password:$("#password").val()},
        success: function(data) {
            data = JSON.parse(data);
            console.log(data);
        }
    });
});
4

1 回答 1

0

This error shows up usually when your backend service (index.php?...) is returning an html page instead of json. Make sure that everything is ok with the server response and double check that you are making the correct ajax call.

I had this error a lot of times and 99% of the cases was some error on the server.

If you are sure that your server response is good, then use a json validator to check the response. Maybe a undesirable character is going unescaped.

于 2013-06-11T23:24:56.463 回答