Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6627675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:02:30+00:00 2026-05-25T22:02:30+00:00

here i am giving the code to preload image by jquery. var _images =

  • 0

here i am giving the code to preload image by jquery.

 var _images = ['/images/ajax-loader.gif'];
   $.each(_images, function (e) {
       $(new Image()).load(function () {
           //alert($(this).attr('src') + 'has loaded!');
       }).attr('src', this);
   });

the above code works fine because here we hard code the image path but when image path is stored in variable then it is not working.

here i am giving the code which gives error.

    var _images = '[' + data.d[0].LabelImagePath + ']';
                        $.each(_images, function (e) {
                            $(new Image()).load(function () {
                                $('#imgHolder').html("<img src='" + data.d[0].LabelImagePath + "' border=0/>");
                                $("#btnPrint").show();
                            }).attr('src', this);
                        });

this line return image path like /images/1Z520777777779.gif.

so please guide me how to preload images when image path is stored in variable with jquery by the above code. thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:02:31+00:00Added an answer on May 25, 2026 at 10:02 pm

    You are building up a string instead of an array (I dunno why). Your $.each() expects something that can be iterated.

    Try creating an array instead, it will work:

    var _images = [data.d[0].LabelImagePath];
    

    Also, inside the $.each(), don’t use data.d[0].LabelImagePath, because it will break your code when you’re trying to preload more than one image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reward: Has been claimed. Overview: The code giving me the problem is deployed here:
here my code- create function dbo.emptable() returns Table as return (select id, name, salary
This code is giving me error on line 10 in IE6. That is, var
Ok so here is the full code it keeps giving me crap about pdf_add_bookmark
here is the portion of code giving me trouble: IF EXIST TH_BUILD_* ( ECHO
Here im giving my code for google map view, this is not working if
here i am giving an image that what kind of tooltip i need. when
Here's a strange one. After renaming a class, one of my forms began giving
Okay, so for some reason this is giving me a error as seen here:
Here is my code, which takes two version identifiers in the form 1, 5,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.