Javascript循环和欺骗关键数据

时间:2015-12-21 10:55:39

标签: javascript ajax

我是ajax的新用户,并且以下查询运行良好,但会收到以下警告

“重复密钥”数据“” 和 “不要使用循环函数”

我应该担心这个,如果是这样,我应该如何解决它们。

    for (var i = 0; i < localStorage.length; i++) 
    {
        var str = localStorage.key(i);
        var dataValue = localStorage.getItem(str);

        if(str.substring(0,5) === "token")
        {   
            $.ajax({
                url: base_url + "task/save_response",
                data: "username="+localStorage.getItem('user')+"&password="+localStorage.getItem('password'),
                data: dataValue,
                type: 'POST',
                dataType: 'json',
            }).done(function(msg) {
                localStorage.removeItem(str);
            });
        }
        else if(str.substring(0,8) === "fileinfo")
        {
            $.ajax({
                    url: base_url + "task/save_file_info",
                    data: "username="+localStorage.getItem('user')+"&password="+localStorage.getItem('password'),
                    data: dataValue,
                    type: 'POST',
                    dataType: 'json',
            }).done(function(msg) {
                localStorage.removeItem(str);
            });
        }
        else if(str.substring(0,5) === "photo")
        {
            uploadPhoto(dataValue);
            localStorage.removeItem(str);
        }
    } //end for

0 个答案:

没有答案