Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
How can I fix this issue when loading an image through a URL action in a javascript button click event

I usually don't ask questions here but this issue has been bugging me for quite a while.

The issue I'm having is that when loading an image into the source of a new image object, it's not loading until the second attempt.

I've looked further into this and I believe what's happening is that: it's loading the image fine the first time, but for whatever reason it's only caching the image at the end of the button click. Meaning that on the first attempt, it has nothing to load from, but on the second attempt, it simply goes off of the newly cached image.

The javascript can be seen below:

    $(document).on('click', '#btnSelectStamp', function () {

        var imageObj = new Image();

        imageObj.id = $(this).attr("value")

        imageObj.src = "@Url.Action("GetMapStamp", "MapMaker")?imageID=" + $(this).attr("value"

        selectedHandle = {
            x: width / 2,
            y: 150,
            isActive: false,
            height: imageObj.height,
            width: imageObj.width,
            rotation: 0,
            image: imageObj,
        }

        $('#SelectImageModal').modal('hide')

        handles.push(selectedHandle)

        draw()

    });

As can be seen above, I'm setting the ID of the new image as what is sent through the button click. The reason for this is because I'm loading the image dynamically through the controller. Then at the point of contention it is setting the image source to a url action.

The controller code can be seen below:

    public IActionResult GetMapStamp(string imageID)
    {
        MapStampItem objMapStamp = MapStampItem.Load(new Guid(imageID));


        return File(objMapStamp.MapStamp, "image/jpeg");

    }

If any more details are needed, please don't hesitate to ask.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!