Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jquery中对beforeSend()上的加载程序进行延迟_Javascript_Jquery_Html_Ajax - Fatal编程技术网

Javascript 如何在jquery中对beforeSend()上的加载程序进行延迟

Javascript 如何在jquery中对beforeSend()上的加载程序进行延迟,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我使用jQueryAjax发布表单数据。加载正在运行beforeSend()函数,但我想让它延迟几秒钟并提交数据 $.ajax({ type : 'POST', url : 'ajax_process_register.php', data : data, beforeSend: function() { //show

我使用jQueryAjax发布表单数据。加载正在运行beforeSend()函数,但我想让它延迟几秒钟并提交数据

$.ajax({

              type : 'POST',
              url  : 'ajax_process_register.php',
              data : data,
              beforeSend: function()
              {
                  //show loader untill getting the response from the ajax.



                  $('.loader').show();
                  setTimeout(function () {
                    $('.loader').hide();
                    th.submit();
                    }, 3000);
              },
              // after getting success response.
              success :  function(data)
              {

装载机没有耽误我的时间。它会立即获得成功

在ajax帖子上执行
setTimeout
<代码>设置超时(ajaxFn,msDelay)

例如:

function ajaxFn() {
    $.ajax({
        type: 'POST',
        url: 'ajax_process_register.php',
        data: data,
        beforeSend: function () {
            $('.loader').show();
            setTimeout(function () {
                $('.loader').hide();
                th.submit();
            }, 3000);
        },
        success: function (data) {

        }
    });
}

// One ms second is 1000
const delayInMs = 3000;

setTimeout(ajaxFn, delayInMs);

怎么做,兄弟?我是jquery新手,你能帮我举个例子吗?为ya=D编辑了一个例子