加载HTML内容为JSON [英] loading html content as a json

查看:137
本文介绍了加载HTML内容为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP和放大器; jQuery的。我使用Ajax调用加载其他一些PHP网页一些巨大的HTML内容了。因为它变得更慢随着时间的推移,我的理解,问题是,我要返回的结果为JSON。 HTML内容的一些HTML内容的表的内部和它的一些事件

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 that , I have to return the result as JSON. The HTML content is of a table of some html contents and some events inside it

但我应该怎么做。什么SPL需要的?

but how should i do this. anything spl needed ?

推荐答案

在你的PHP页面返回的HTML内容,你可以这样做:

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
// <table>...............</table>
$html = json_encode(array('html'=>$html));
echo $html;
die;

在JavaScript中,你可以做这样的事情:

In the javascript, you could do something like this:

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

这篇关于加载HTML内容为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆