如何从jquery $ .get获取返回值?

时间:2015-11-24 10:47:04

标签: jquery get jquery-get

贝娄是我的代码。它现在有效,但如果我删除以下行警告(currentIntervalPosition +“__ 1”);从getIncidentTime函数,代码将无法工作,我需要删除该行。当我说代码不起作用时,意味着在initializeVideoInformation函数中,在getIncidentTime调用之后,变量currentIntervalPosition是未定义的。 如何访问返回的数据?

   function initializeVideoInformation(json) {
        $.each(json, function(idx, obj) {
            if (obj) {
                var result = obj.timeStamp.split(" ");
                var dateFolder = result[0].replace(/-/g, "_");
                var videoName = result[1].substr(0, 2);
                var videoFileWithPath =  "/video/"+dateFolder+"/"+videoName;
                var syncFile = videoFileWithPath + ".sync";
                videoFileWithPath += ".mp4";

                var currentIntervalPosition = getIncidentTime(syncFile, result[1]);
                getVideoScreenShot(videoFileWithPath, currentIntervalPosition, idx);
            }
        });
    }

    function getIncidentTime(syncFile, incidentTime) {
        var currentIntervalPosition;
        $.get(syncFile, function(json) {
            var fileContent = JSON.parse(json);
            var fps = fileContent.fps;
            var frames = fileContent.frames;
            var syncData = [];

            for (var index=0; index<frames.length; index++) {
                syncData[index] = timeToMillies(frames[index].t);
            }

            var jumpTime = timeToMillies(incidentTime);
            var BinaryIndex = BinarySearch(jumpTime, syncData);
            var currentTime = (1 + BinaryIndex) / 25 + 0.0001;    // fps

            var frameNo = Math.floor(25*currentTime) - 1;   //fps
            currentIntervalPosition = syncData[frameNo];
        });

        alert(currentIntervalPosition+"__1");
        return currentIntervalPosition;
    }

0 个答案:

没有答案