Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firefox中Jquery的Ajax Json问题_Javascript_Jquery_Ajax_Json_Firefox - Fatal编程技术网

Javascript Firefox中Jquery的Ajax Json问题

Javascript Firefox中Jquery的Ajax Json问题,javascript,jquery,ajax,json,firefox,Javascript,Jquery,Ajax,Json,Firefox,在jQuery调用中使用ajax生成json响应时遇到了一些问题。基本上,我正在尝试获取特定目录中的所有图像。下面是我的jQuery代码,对于图像少于50个的目录来说,这很好,但是一旦图像数量超过50个,Firefox就会中止请求。这在Safari、Chrome和IE中都很管用。要么他们做错了,Firefox做对了,而我犯了一个错误,要么这是Firefox成为罪魁祸首的罕见时刻之一。我尝试过$.getJSON并禁用ajax请求的缓存,但这似乎也不起作用。我们将非常感谢您的帮助 var a

在jQuery调用中使用ajax生成json响应时遇到了一些问题。基本上,我正在尝试获取特定目录中的所有图像。下面是我的jQuery代码,对于图像少于50个的目录来说,这很好,但是一旦图像数量超过50个,Firefox就会中止请求。这在Safari、Chrome和IE中都很管用。要么他们做错了,Firefox做对了,而我犯了一个错误,要么这是Firefox成为罪魁祸首的罕见时刻之一。我尝试过$.getJSON并禁用ajax请求的缓存,但这似乎也不起作用。我们将非常感谢您的帮助

    var activeRequest = false;
    var error = "The system could not read the directory at this time.";
    var current = this.location['href'];

    var filesCache = {};
    function addFile(list, varToAdd, path, id){
        if (typeof varToAdd != 'undefined' && varToAdd != null ){
            var imagePath = path;
            var srcPath = path+"/"+varToAdd['file'];
            imagePath = "/cms/images/thumbs/"+imagePath+varToAdd['file'];

            var filename = varToAdd['file'];
            if(filename.length >18){
                filename = filename.substr(0, 15)+"...";
            }

            var fileInfo = '<li id ="'+varToAdd['file'].replace('.', '')+'">';
                fileInfo += '<a class = "thumb" href="'+srcPath+'" target="_blank"><img src="'+srcPath+'" width="'+varToAdd['width']+'" height="'+varToAdd['height']+'" alt="'+varToAdd['file']+'" /></a>';
                fileInfo += '<ul class="fileInfo"><li title="'+varToAdd['file']+'">'+filename+'</li><li>'+varToAdd['dims']+'px</li><li>'+varToAdd['size']+'kb</li></ul>';
                fileInfo += '</li>';

            list.append(fileInfo);
            delete fileInfo;
        }

        else
            return false;

    }
    function lookupFiles(path){
        var cleanPath = decodeURIComponent(path);
        cleanPath += "/";
        var urlLookUp = '/cms/images/lookup/file/?path='+encodeURIComponent(cleanPath);

        var loader = $(".folder-contents .header");
        $.ajaxSetup({
                cache: false
        });
        var ajaxRequest = $.ajax({
            type: 'GET',
            url: urlLookUp,
            data: path,
            dataType: 'json',
            beforeSend: function (request) {
                if(!activeRequest)
                    loader.addClass('loading');
                else
                    return false;
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    loader.addClass('error').removeClass('loading');
                    alert(error);
                },
                success: function(response, status, XMLHttpRequest) {
                    list = $(".folder-contents >  ul.files");
                    if(typeof response != 'undefined' && response != null){
                        if(status == 'success' && (typeof response.files != 'undefined' && response.count > 0)){
                            list.empty();
                            $.each((response.files), function(index, value) {
                                addFile(list, value, path, response.searchTerm);
                            });
                            //list.append('</ul>');

                        }
                        else if (status == 'success' && (typeof response.files != 'undefined' && response.count == 0)){
                            list.empty();
                            list.append('<li class = "noresults">There are no images in this folder</li>');

                        }
                        else{
                            formLabel.addClass('error').removeClass('loading');
                            alert('Error');
                        }
                    }
                    loader.removeClass('loading');
                }
            });
    /*
            var json = $.getJSON( urlLookUp+"format=json&jsoncallback=?", function ( data ) {
                                 console.log( data ); 
                                } );
    */
    }



    $(document).ready(function() {
        $("a.directory").live('click',function(ev){
            ev.preventDefault();

            if($(this).hasClass('open')){
                $(this).addClass('empty').removeClass('open').html('-');
                lookup($(this).attr("title"));
            }
            else if($(this).hasClass('close')){
                $(this).addClass('open').removeClass('close').html('+');
                $(this).parent().find('ul').remove();               
            }

        }); 

        $("a.folder").live('click',function(ev){
            ev.preventDefault();
            lookupFiles($(this).attr("title"));
        });

        $(".files li").live('click', function(ev){
            ev.preventDefault();

            // send ckeditor back what image was selected - url from jquery selector & callBack from the view
            var fileUrl = $(this).find('a').attr("href");
            var callBack = window.CKEditorFuncName;

            window.opener.CKEDITOR.tools.callFunction(callBack, fileUrl);   
            window.close();
        });

    });

为什么要在ajax调用中通过url和数据参数传递path参数?这只是额外的一行代码,我删除了它,问题仍然存在,data:path没有做任何可能重复的事情