jQuery.ajax({ type: 'POST', url: 'ajaxform/captchaimg.php', beforeSend: function(){ $('#spanimg').html('<img id="imgcode" src="ajaxform/loadinfo.gif">'); }, success: function(msg){ $('#spanimg').html(msg); }