jquery - Ajax request is not working when it called image handler -
my buttons click event handler this;
$(".imgrefreshcontact").click(function () { $.ajax({ url: "/presentation/site/handlers/refreshcaptcha.ashx", type: "post", cache: false, async: true, success: function () { } }); $("#imgcaptcha").attr('src', '/presentation/site/handlers/createcaptcha.ashx'); });
refreshcaptcha handler;
public void processrequest(httpcontext context) { context.session["captchametin"] = confirmcode.generaterandomcode(); }
createcapthca handler;
public void processrequest(httpcontext context) { confirmcode cc = new confirmcode(context.session["captchametin"].tostring(), 136, 36); context.response.clear(); context.response.contenttype = "image/jpeg"; cc.image.save(context.response.outputstream, system.drawing.imaging.imageformat.jpeg); cc.dispose(); }
when clicked img button, it's working perfect in chrome , firefox fails in ie 9 debugger enters refreshcaptcha handler not enters createcaptcha handler. so, ie makes ajax request once, not second time.
what problem ie , ajax request
use ie developer tools (f12) debug request. ie caches request , if don't change returns 304 status code (not modified). prevent this, add random query string parameter ajax call. like:
url: "/presentation/site/handlers/refreshcaptcha.ashx?rnd=" + math.random()
Comments
Post a Comment