asp.net mvc jquery填充图片
我想点击capthca时重新填充图像。 我怎样才能做到这一点?
public ActionResult Image() { var builder = new XCaptcha.ImageBuilder(); var result = builder.Create(); Session.Add("Cap", result.Solution); return new FileContentResult(result.Image, result.ContentType); } $(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="" alt="Click to refresh" />
$('#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; });
尝试将src属性设置为动态图像url的url