0

I have a list of files, and for each file, on click event, I get the file name and parse the file name and get the extension type:

extension = $('#'+id_href).text().split('.').pop();

Now, a ajax call should be made in order to fetch data about the current file extension.

I want to prevent the ajax api call if I already have the extension data saved in my extension array.

My extension array looks like: a[extension_1] = html_data_1, a[extension_2] = html_data_2;

I want to check if the position extension_1 already exists, and if not, a ajax call should be made to retrieve the data;

with what should i replace the if(!array_extension[extension]) line?

var array_extension = new Array();

ImgAjaxLoader = "$url_img"+'ajax-loader.gif';
ImgI = "$url_img"+'info_icon.png';
$("html").live("click", function() {
    $(".info_box").hide();
});
$(".info").live("click",function(e){
    e.stopPropagation();
    var elem = $(this);
    $(".info_box").hide();
    position = $(this).offset();
    var id = 'container_tooltip';
    var id_img = $(this).attr('id');
    var id_href = $(this).attr("id").replace("image_","href_");
    $('#'+id_img).attr('src',ImgAjaxLoader);
    $('#'+id).toggle(100, function() {
        if($(this).css('display') == 'block') {
            extension = $('#'+id_href).text().split('.').pop();
            //if(!array_extension[extension])
            $.ajax({
                url: "$url",
                data: { document_id:elem.attr('document_id') },
                success: function (response) {
                    //console.log(response);
                    response = JSON.parse(response);
                    array_extension[response.extension] = response.html;
                    $('#'+id).html(response.html);
                    $('#'+id).css({'top':(position.top-110)+'px','left':(position.left+30)+'px'});
                    $('#'+id_img).css({'width':'20px','height':'20px',"padding":"0px"});        
                    $('#'+id_img).attr('src',ImgI);
                }
            });
            }
        });
});
Ionut Flavius Pogacian
  • 4,750
  • 14
  • 58
  • 100
  • 2
    check http://stackoverflow.com/questions/1098040/checking-if-an-associative-array-key-exists-in-javascript – Kek Aug 14 '13 at 08:11
  • and this http://stackoverflow.com/questions/135448/how-do-i-check-to-see-if-an-object-has-a-property-in-javascript – Nicolae Olariu Aug 14 '13 at 08:17

0 Answers0