打通jQuery的AJAX图像 [英] Get an image through jQuery AJAX

查看:116
本文介绍了打通jQuery的AJAX图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的图像标记是在我的登录页

 < IMG ID =CaptchaImgALT =验证码SRC =@ url.action(验证码,登录)的风格=/>

现在,当我刷新我的登录页面,它工作正常,从控制器获取图像,但是当我退出和登录页面呈现.the控制器方法是不是被called.Problem只在IE浏览器上正常工作。就是周围有工作?
我可以做一些与jQuery Ajax调用到控制器,我试过,但成功的方法没有被调用。有没有其他办法?

  $。阿贾克斯({
    键入:GET,
    网址:'/登录/ CaptchaImage',
    数据类型:形象,
    成功:功能(数据){
        调试器
        $('#CaptchaImg')ATTR('src'中的数据)。
    }
});


解决方案

试试这个

  $。阿贾克斯({
    键入:GET,
    网址:'@ Url.action(验证码,登录)',
    数据类型:图像/ JPG
    成功:功能(数据){
        $('#CaptchaImg')ATTR('src'中的数据)。
      }
 });

The following image tag is in my Login Page

<img id="CaptchaImg" alt="Captcha" src="@url.action("Captcha","Login")" style="" />

Now when I refresh my login Page, it works fine, and gets the image from the controller, but when I logOut and the login Page renders .the controller method is not being called.Problem is only in IE works fine on Chrome.Is there are work around? Can I do something with jQuery Ajax call to the controller, I tried this but the success method is not called. Is there any other way?

$.ajax({
    type: "GET",
    url: '/Login/CaptchaImage',
    datatype: "image",
    success: function(data) {
        debugger
        $('#CaptchaImg').attr('src', data);
    }
});

解决方案

Try this

$.ajax({
    type: "GET",
    url: '@Url.action("Captcha","Login")',
    dataType:"image/jpg",
    success: function (data) {
        $('#CaptchaImg').attr('src', data);
      }
 });

这篇关于打通jQuery的AJAX图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆