gpt4 book ai didi

javascript - 为什么在 asp.net mvc 中更改图像链接会异步调用 Controller

转载 作者:行者123 更新时间:2023-12-02 18:26:17 25 4
gpt4 key购买 nike

我正在更改客户端图像的链接,它会异步调用 Controller 。

我不明白这种行为,有人可以解释一下发生了什么吗?

为什么 url 添加实际上默认会调用 Controller ,而且它是异步发生的。

    <script>
$("#refreshLnk").click(function () {
$("#cap").attr('src', '@Url.Action("CaptchaImage")?' + new Date().getTime());
});
</script>

<img id="cap" alt="Captcha" src="@Url.Action("CaptchaImage")" style="" />
<a id="refreshLnk" href="#">refresh</a>

public ActionResult CaptchaImage()
{
}

最佳答案

这是正常且预期的行为。单击该按钮时,脚本会将图像的 src 属性更改为“/CaptchaImage?1376967614675”之类的内容。浏览器尝试渲染图像,从而调用此 url。这会触发 Controller 中的 CaptchaImage 方法。

与您的问题相关的帖子有很多,您可以从这个开始:How does Url.Action work Asp.net MVC? 。希望对您有帮助!

关于javascript - 为什么在 asp.net mvc 中更改图像链接会异步调用 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18325782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com