0

Somehow the code to setup src for image tag does not work at all.

But if I put directly url in browser or update page the url is working fine.

It seems like

var tsPath = '@Url.Action("UpdatedLogo", "Logo")';
$('#logo').attr("src", tsPath);

is not firing at all.

What I am missing?

$.ajax({
            type: "POST",
            url: '@Url.Action("Logo", "Users")',
            data: JSON.stringify(params),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {

                // It is not working :(
                var tsPath = '@Url.Action("UpdatedLogo", "Logo")';
                $('#logo').attr("src", tsPath);

            },
            error: function () {
                alert("Timeout error.");
            }
        });

C#

 public ActionResult UpdatedLogo()
        {
                // ... some code
                    using (var stream = new MemoryStream())
                    {
                        image.Save(stream, ImageFormat.Png);
                        return File(stream.ToArray(), "image/png");
                    }

        }

P.S. What I found that when I do it first time it happens and all next click dont have any effect. And at the same time no errors.

Could be that Browser is caching image somehow? Or what it is?

NoWar
  • 36,338
  • 80
  • 323
  • 498

1 Answers1

0

I found whatsup.

Here is an answer How to reload/refresh an element(image) in jQuery

I did following

var tsPath = '@Url.Action("UpdatedLogo", "Logo")';
$('#logo').attr("src", tsPath + "?&d=" + Math.floor(Math.random() * 1000));

Yeah! :)

Community
  • 1
  • 1
NoWar
  • 36,338
  • 80
  • 323
  • 498