在发送第一个值后延迟运行Jquery 2秒

时间:2013-09-22 21:49:21

标签: jquery ajax delay settimeout intervals

function randomQuote () {
     $('#decoded').val($.scriptcam.getBarCode());
     var decoded = $('#decoded').val();
     if(decoded != ""){

     $("#avatar").html('<img src="database/img/picloader.gif" style="height:150px;width:150px;"/> ');
     //alert(decode);
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "database/dataLog.php",
                data: {
                        decoded: decoded
                },
                cache: false,
                success: function(data){
                    $("#avatar").html(data.avatar);
                    $("#profile").html(data.profile);
                    $("#log").html(data.log);
                    $("#sfx").html(data.sfx);

                    setTimeout(function() {
                    $("#avatar").html('<img src="database/img/avatar.jpg" style="height:150px;width:150px;"/> ');
                    $("#profile").html('');
                    $("#log").html('');
                    $("#sfx").html('');
                    }, 15000);

                }
            });

     }

如何延迟在jquery中发送值,代码发送信息太快,有时它发送它的两倍或三倍,我想要的是当jquery获得1值时它会将它发送给ajax并且它不会接受另一个值为2秒。那可能吗?

0 个答案:

没有答案