AJAX json unexpected token '

后端 未结 2 859
太阳男子
太阳男子 2021-01-20 04:26

I have this code:

    $.ajax({
            dataType: \'text\',
            url: \'/_/js/answers.json\',
            type: \"GET\",
            success: funct         


        
2条回答
  •  长情又很酷
    2021-01-20 04:51

    Try changing dataType to JSON:

    $.ajax({
        dataType: 'JSON',
        url: '/_/js/answers.json',
        type: "GET",
        success: function (data) {
            alert(data);
            alert(data.code);
            var result = JSON.parse(data);
            var hey = JSON.parse('{"code": 123}'); 
            alert(hey.code);
            alert(result.code);
        },
        error: function () {
            alert("code not found");
        }
    });
    

提交回复
热议问题