.filter无法使用我的服务器上的javascript过滤json响应

时间:2015-10-27 12:28:22

标签: javascript json filter

我使用.filter()函数从json响应中过滤数据。它在我的本地系统上工作正常,但是当我在服务器上上传代码时,我收到错误respose.filter is not a function

我的代码是:

$.get( 'js/question.json', function(response) {
    var newres = response.filter(function(x){ return x.difficulty == q_id; });
    if(last_id!='')
        newres = newres.filter(function(y){ return y.id != last_id; });

    newres = shuffle(newres);

    level_e1 = newres[0].question;
    console.log(level_e1);
    level_left_e1 = newres[0].type;
    questionId = newres[0].id;

    CopyOfInit();

    correct_answer = 0;
    wrong_answer = 0;
});

response is

[{
    "id": "5402",
    "question": ["a", "b", "c"],
    "answer": "1",
    "difficulty": "1",
    "game_name": "Alphabet",
    "notes": "Drag and drop alphabet cards to the empty slots",
    "question_id": "13CA9999",
    "question_type": "A B C",
    "type": "left1_e1"
}, {
    "id": "5403",
    "question": ["b", "c", "d"],
    "answer": "1",
    "difficulty": "1",
    "game_name": "Alphabet",
    "notes": "Drag and drop alphabet cards to the empty slots",
    "question_id": "13CA9998",
    "question_type": "B C D",
    "type": "left1_e1"
}]

这可能是什么问题?
这是我的托管服务器问题还是我的代码出了问题?

0 个答案:

没有答案