我怎么能替换图片Ajax调用期间与加载图像TD内 [英] How can I replace image inside a TD with loading image during Ajax call

查看:74
本文介绍了我怎么能替换图片Ajax调用期间与加载图像TD内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML表格。在每个小区存在一个图像接着一些文本。事情是这样的:

I have an HTML table. In each cell there is an image followed by some text. Something like this:

<td>
  <img src='image.gif'>This is a test
</td>

我要运行一个jQuery Ajax调用这个通话过程中我想的图像更改为加载图像,我有(loading.gif),然后(在这种情况下Image.gif的)恢复为常规图像后,阿贾克斯是完整的。

I have to run a jQuery Ajax call and during this call I want to change the image to a loading image that I have (loading.gif) and then return it to the regular image (image.gif in this case) after the Ajax is complete.

什么是正确的jQuery的语法将图像切换到加载图像,然后再返回?

What is the correct jQuery syntax to change the image to the loading image and back again?

推荐答案

我相信你的问题是关于如何将一个AJAX请求之前改变图像,然后当AJAX请求完成它改回来。

I believe your question is regarding how to change an image before an AJAX Request and then change it back when the AJAX request is finished.

那么下面是一个示例...这里是一些参考 jQuery的阿贾克斯()方法。注:阿贾克斯()方法中包含的选项申报成功,错误和完整的功能,可以当AJAX调用成功执行,出现了错误,或完成(即成功或错误之后)

Well below is a sample...and here is some reference to the jQuery ajax() method. Note: the ajax() method contains options to declare success, error and complete function that can be executed when the AJAX call is successful, errors out, or is completed (ie after either success or error).

<td>
  <img id="loadingImg" src='image.gif'>This is a test
</td>


$("#loadingImg").attr("src", "loading.gif");
$.ajax({ //other options here
  complete: function () {
  $("#loadingImg").attr("src", "image.gif");  // change image back when ajax request is complete
} });

这篇关于我怎么能替换图片Ajax调用期间与加载图像TD内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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