weixin_33694620 2016-11-07 19:19 采纳率: 0%
浏览 29

PHP流和jQuery

What is the best way to display or deal with a large result on success while waiting for PHPto render that result. I would like to use jQuery to submit a form, have PHP process it, and give output/feedback to users while they wait (either in a div or an iframe...in the example below I use an iframe).

I have the backbone of the xhr version that I found online, but I was wondering if there is a better way (I am aware that there is jquery mixed into this:

function submitForm(){
    $('#report_iframe').attr('src','/tests/stream_ajax/blank_iframe.php'); 
     $("#report_modal").modal({backdrop: "static"});

       count=1;
         xhr = new XMLHttpRequest();
         xhr.open("GET", "/folder/ajax_result.php", true);
         xhr.onprogress = function(e) {
           count = count +1;

         $( "#report_iframe" ).contents().find( "#content_loader" ).text('this is jquery count' + count);
         }
         xhr.onreadystatechange = function() {
           if (xhr.readyState == 4) {
             //console.log("Complete = " + xhr.responseText);
            // alert("complete");

             document.getElementById("report_iframe").srcdoc=xhr.responseText;
           }
         }
         xhr.send();



};

Any help appreciated. Thanks.

J Doyle

  • 写回答

2条回答 默认 最新

  • lrony* 2016-11-07 19:37
    关注

    Anyway you are using JQuery. Why don't you use JQuery ajax ?

    $.ajax({
             cache: false,
             async: true,
             type: "GET",
             url: '/folder/ajax_result.php',
    beforeSend:function()
    {
        count = count +1;
    },
    success:function(response)
    {
        document.getElementById("report_iframe").srcdoc=response;
    }
         });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗