I have page which send request to a php for getting some data and in response to that request of php returns me something like this:-

我有页面发送请求到PHP获取一些数据,并响应php的请求返回我这样的事情: -

[{"postID":"1","0":"1","userID":"3","1":"3","imagePath":"images\/31481440272.jpg","2":"images\/3-1481440272.jpg","postDate":"11 December 2016","3":"11 December 2016","postDescription":"trying","4":":D trying"}]

What I want is to make a dynamic html table inside a specific div

我想要的是在特定div中创建一个动态html表

<div id="dataWillBeShownHere"></div>

What will I do if records will be more than 1.Should I use for each loop for more than one record.

如果记录超过1,我该怎么办。我应该为每个循环使用多个记录。

I am really confused in this thing. Somehow I know the solution but cannot implement.

我真的很困惑这件事。不知怎的,我知道解决方案,但无法实现。

I hope you have understand my question.

我希望你能理解我的问题。

1 个解决方案

#1


1

You can do this with simple javascript and html:

你可以用简单的javascript和html做到这一点:

<script type="text/javascript">
var records = [];
// This data could be retrieved from an ajax $.post
var data = {"postID":"1","0":"1","userID":"3","1":"3","imagePath":"images\/31481440272.jpg","2":"images\/3-1481440272.jpg","postDate":"11 December 2016","3":"11 December 2016","postDescription":"trying","4":":D trying"};

// Add our data to the records array
records.push(data);

// Get how many record we have
var record_count = records.length;

// Parse data to html tables
for (var i = records.length - 1; i >= 0; i--) {
    var html = "";

    // make your html additions here
    html += "<div> ID: " + records[i]["postID"] + "</div>";
    html += "<div> Date: " + records[i]["postDate"] + "</div>";
    // html += ;
    // html += ;

    // Now use jquery selector to write to the div
    $('#data-table').html(html);
};
</script>


<div id="data-table"></div>

Check my JSFiddle

检查我的JSFiddle

更多相关文章

  1. 等待执行所有ajax回调的最佳解决方案
  2. 【问题解决方案】ImportError: No module named 'pygal'
  3. Python 黏包及黏包解决方案
  4. 无法安装ndg-httpsclient或者我的解决方案错误
  5. Linux无法连接网络解决方案
  6. Media-S 简介(一个开源的DRM解决方案)
  7. AppScan安全问题解决方案
  8. PLSQL乱码解决方案
  9. 数据库不支持中文解决方案(mysql)

随机推荐

  1. Android Activity去除标题栏和状态栏
  2. android摄像头采集和预览-第二种方法
  3. android textView加边框
  4. xarmain使用Forms编译android工程出现sup
  5. 2013.04.03——— android 图片缓存之二L
  6. Android(安卓)AbsListView
  7. Android Shape关键字意思
  8. Android开发由eclipse转Android Studio中
  9. Android 的相对布局的一些使用
  10. Android 6.0关于电话的各种Call和Connect