loading html content as a json

后端 未结 3 800
死守一世寂寞
死守一世寂寞 2021-01-16 10:41

I am using php & jquery. I use ajax calls to load some huge html content got from some other php page. As it gets slower as time goes, i understood that the problem is t

3条回答
  •  礼貌的吻别
    2021-01-16 11:19

    In your PHP page that returns the html content, you can do this:

    // $html should contain the html code you want to return, e.g
    // ...............
    $html = json_encode(array('html'=>$html)); echo $html; die;

    In the javascript, you could do something like this:

    function getHtml()
    {
        $.getJSON("yourphpPage.php", function (result)
           {
               $("#yourHtmlDiv").html(result.html);
           }
         );
    }
    

提交回复
热议问题