Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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 为什么不显示Ajax调用之前的文本? 函数pdfToImgExec(文件、IsfirstLogging、文件夹、循环){ 警报(文件); var postString=file+'&'+IsfirstLogging+'&'+folder+'&'+round; var errorMsg=(文件夹==“传入”?“_Javascript_Jquery_Ajax_Asynchronous_Synchronization - Fatal编程技术网

Javascript 为什么不显示Ajax调用之前的文本? 函数pdfToImgExec(文件、IsfirstLogging、文件夹、循环){ 警报(文件); var postString=file+'&'+IsfirstLogging+'&'+folder+'&'+round; var errorMsg=(文件夹==“传入”?“

Javascript 为什么不显示Ajax调用之前的文本? 函数pdfToImgExec(文件、IsfirstLogging、文件夹、循环){ 警报(文件); var postString=file+'&'+IsfirstLogging+'&'+folder+'&'+round; var errorMsg=(文件夹==“传入”?“,javascript,jquery,ajax,asynchronous,synchronization,Javascript,Jquery,Ajax,Asynchronous,Synchronization,传入文件夹中的错误:”其他文件夹中的错误“”; $.ajax({ 类型:“POST”, cache:false, async:false, url:“pdfToImgExec.php”, 数据:{ “数据”:postString }, 数据类型:“html”, beforeSend:函数(){ 警报(文件+‘a’); $('pdfToImgResult').html('p>正在转换'+file+',请稍候……'); }, 成功:功能(数据){ 如果(数据='1'){ $('#pdfToImgRe

传入文件夹中的错误:”其他文件夹中的错误“

”; $.ajax({ 类型:“POST”, cache:false, async:false, url:“pdfToImgExec.php”, 数据:{ “数据”:postString }, 数据类型:“html”, beforeSend:函数(){ 警报(文件+‘a’); $('pdfToImgResult').html('p>正在转换'+file+',请稍候……

'); }, 成功:功能(数据){ 如果(数据='1'){ $('#pdfToImgResult').html('Complete convert'+file+'

'); }否则如果(四舍五入){ $('pdfToImgResult').html('p>转换失败,重试'+round+'round

'); round++; pdfToImgExec(文件“假”、文件夹、圆形); }否则{ 文件夹==“传入”?tempFailIncomingFiles.push(文件):tempFailResultFiles.push(文件); } }, 错误:函数(x,t,m){ $('#pdfToImgResult').html(errorMsg); 警报(t); releaseBtn(); } }); } 这个ajax调用的问题是我可以在beforeSend函数中警告(file+'a'),但是

function pdfToImgExec(file, IsfirstLogging, folder, round) {
  alert(file);
  var postString = file + '&' + IsfirstLogging + '&' + folder + '&' + round;
  var errorMsg = (folder == 'Incoming' ? '<p>error in incoming folder</p>' : '<p>error in other folder</p>');
  $.ajax({
    type: "POST",
    cache: false,
    async: false,
    url: "pdfToImgExec.php",
    data: {
      "data": postString
    },
    dataType: "html",
    beforeSend: function () {
      alert(file + 'a');
      $('#pdfToImgResult').html('<p>Converting' + file + ', Please wait......</p>');
    },
    success: function (data) {
      if(data == '1') {
        $('#pdfToImgResult').html('<p>Complete convert ' + file + '</p>');
      } else if(round < 4) {
        $('#pdfToImgResult').html('<p>Fail to convert , retry ' + round + ' round <img src="loading.gif" height="20" width="20"/></p>');
        round++;
        pdfToImgExec(file, 'false', folder, round);
      } else {
        folder == 'Incoming' ? tempFailIncomingFiles.push(file) : tempFailResultFiles.push(file);
      }
    },
    error: function (x, t, m) {
      $('#pdfToImgResult').html(errorMsg);
      alert(t);
      releaseBtn();
    }
  });
}
$('#pdfToImgResult').html('正在转换'+file+',请稍候……

');
不工作时,它不会显示任何内容,只会跳转到

$('#pdfToImgResult').html('<p>Converting' + file + ', Please wait......</p>');
$('#pdfToImgResult').html('Complete convert'+file+'

');
ajax调用完成后


这是由于
async:false
?如何解决这个问题?谢谢。

这是因为您使用的是
async:false,
,所以函数会一直阻塞,直到请求完成,防止在完成所有操作之前重新绘制

您似乎都设置了回调,所以似乎没有任何理由发出阻塞xhr请求。只需删除
async:false,
,就可以全部设置好了


下面是一个如何处理异步代码的快速示例。我删除了你的大部分代码以保持简洁

$('#pdfToImgResult').html('<p>Complete convert ' + file + '</p>');

这是因为您使用的是
async:false,
,因此函数会一直阻塞直到请求完成,从而防止在完成所有操作之前重新绘制

您似乎都设置了回调,所以似乎没有任何理由发出阻塞xhr请求。只需删除
async:false,
,就可以全部设置好了


下面是一个如何处理异步代码的快速示例。我删除了你的大部分代码以保持简洁

$('#pdfToImgResult').html('<p>Complete convert ' + file + '</p>');

thx的回答,我已经把显示语句在beforeSend功能,我已经尝试了警报弹出窗口,它是工作。只有更改html元素的语句不可用working@user782104:显示
警报()
不需要重新绘制页面。更新元素的
.html()。在函数完成之前,您将阻止重画。async:false是维护程序顺序所必需的。。为什么它会阻止html(),因为我已经将它放在BeforeSend中了?为了回答这个问题,我已经将display语句放在BeforeSend函数中,并且我已经尝试了警报弹出窗口,它正在工作。只有更改html元素的语句不可用working@user782104:显示
警报()
不需要重新绘制页面。更新元素的
.html()。在函数完成之前,您将阻止重画。async:false是维护程序顺序所必需的。。为什么它会阻止html(),因为我在发送之前就已经把它放进去了?
pdfToImgExec(..., ..., ..., ..., function(data) {
    // resume your code here.
    alert(data);
})