静态页面调用PHP获得数据再格式化显示

WBOY
Release: 2016-06-23 13:33:16
Original
995 people have browsed it

我们现在已经有一些PHP代码,调用相关接口可以返回JSON数据。我现在想实现在HTML里调PHP,把返回的数据输出到HTML里。请问这样做现实么?(注意,PHP部分只是返回JSON数据,而不是写上Document.Write之类的东西)

举个例子,调PHP接口会返回一个JSON数据,我希望HTML里能显示一个表格来显示这些内容。

我是个客户端开发人员,了解一点前端的皮毛。之所以这样做是因为原来要内嵌浏览器打开服务端做的某几个页面,但有几个页面的性能特别糟糕且没人能调(据说用了很先进的框架),所以我现在想出了整个办法。


回复讨论(解决方案)

执行的页面必须是.php结尾的,才能解析php,执行php的逻辑要用包起来
获取到json数据后,json_decode($json,true);就是一个数组,可以打印出来看一下
将数组的值嵌到你要显示地方就可以,如:

通过ajax获取数据,然后嵌入到页面里就行了

用ajax 调用你返回json数据的php接口,然后用js解析json 在页面上显示

用ajax 调用你返回json数据的php接口,然后用js解析json 在页面上显示

一个简单的例子,参考下。

'fdipzone','gender'=>'male'),    array('name'=>'tom','gender'=>'male'),    array('name'=>'lucy','gender'=>'female'),);?>      New Document          
Copy after login

谢谢各位,最后不用这种方法了。
如果用页面方式,就请专门的前端开发人员调试,我自己还是从客户端技术想办法。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!