Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda