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;
    }
         });
    
    评论

报告相同问题?