尝试获取文件时,Chrome中的“网页无响应”错误> 500KB

时间:2014-11-20 04:23:40

标签: javascript jquery ajax google-chrome webkit

我正在尝试在我的应用程序中获取日志文件,并且正在使用Ajax来执行此操作。

问题在于,在使用Chrome时,我经常会遇到“无响应”的问题。我尝试加载文件时出错。 我的应用程序在Firefox中工作正常,所以我猜这是一个webkit问题。 我删除了xhr,因为我听说chrome有问题。

这是我的代码 -

$.ajax(
    {
        type: 'GET',
        url: "Logs/GetLogFile?option=" + logFile,
        data: {},
        success: function (data) {
            var fileData = data;
            cleanUp();
            currentlyViewedFile = logFile;
            var fileLines = fileData.split('\n');

            var htmlString = '';
            var lineCount = 0;
            for (var i = 0; i < fileLines.length; i++) {
                lineCount = lineCount + 1;
                if (i == (highlightLine - 1)) {

                    htmlString += '<span id="highLoc" style="display:block"><font size="4" color="red">' + lineCount + '. ' + fileLines[i] + '</font></span>';
                }
                else {
                    htmlString += '<span class="spanClass">' + lineCount + '. ' + fileLines[i];
                }

                var combinedLine = fileLines[i];

                var isNewLogLine = false;
                var newLogLineCount = 0;
                while (((i + newLogLineCount + 1) < fileLines.length) && (isNewLogLine == false)) {
                    var NextlogLine = fileLines[i + newLogLineCount + 1].split(' ');
                    isNewLogLine = isLogLine(NextlogLine[0]);
                    if (isNewLogLine == true) {
                        break;
                    }

                    htmlString += fileLines[i + newLogLineCount + 1];
                    combinedLine += fileLines[i + newLogLineCount + 1];
                    newLogLineCount = newLogLineCount + 1
                }

                i = i + newLogLineCount;
                var logLine = combinedLine.split(' ');
                var logMsgStartIndex = combinedLine.indexOf(logLine[5]);
                var logMsg = combinedLine.substring(logMsgStartIndex);

                var obj = {
                    lineNos: lineCount,
                    date: logLine[0],
                    time: logLine[1],

                    severity: logLine[2],
                    logClassName: logLine[4],
                    logMessage: logMsg
                };
                fileArray.push(obj);

                if ((i % 1000) == 0) {

                    $("#textPlace").append(htmlString);
                    htmlString = '';
                    window.scrollTo(0, 2);
                }

            }
            fileLines = null;
            $("#fetchProgress").hide();
            $("#textPlace").append(htmlString);
            //highlight error location
            var scrollX = $("#highLoc");
            if (scrollX) {
                if (!scrollX[0]) return;
                var scrollDistance = '{ scrollTop: ' + scrollX[0].offsetTop + '}';
                var distanceInJson = eval("(" + scrollDistance + ")");
                $("#mainContentBox").animate(distanceInJson, 1);
            }
        },
        ///success function end
        fail: function (jqXHR, textStatus) {
            alert("Request failed: " + textStatus);
        }
    });

如果有人对如何处理这个问题有任何想法,请告诉我。

0 个答案:

没有答案