本文介绍了asp.net mvc jquery填充图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我单击capthca时,我想重新填充图像.我该怎么办?
i want to refill the image when i click on the capthca . how can i do that?
public ActionResult Image()
{
var builder = new XCaptcha.ImageBuilder();
var result = builder.Create();
Session.Add("Cap", result.Solution);
return new FileContentResult(result.Image, result.ContentType);
}
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#images').click(function () {
$.ajax({
url: "/en/form/Image",
success: function (mydata) {
$("#images").attr("src", mydata);
},
type: "POST"
});
return false;
});
});
<input type="image" id="images" src="<%= Url.Action("Image", "ContactForms") %>"
alt="Click to refresh" /> <input type="text" size="5" tabindex="1000" dir="ltr" maxlength="5" name="Captcha" id="Captcha" />
推荐答案
$('#images').click(function () {
$(this).attr('src', function() {
// the datetime portion appended to the url avoids caching issues
// and ensures that a fresh image will be loaded every time
var d = new Date();
return this.src + '?' + d.getTime();
});
// Remark: not sure about the return false here. This will cancel the
// default action of the image button => might not be what you need =>
// adapt to your requirements
return false;
});
这篇关于asp.net mvc jquery填充图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!