简体   繁体   English

如何通过从php接收json响应来生成带有jquery的动态表

[英]How to generate dynamic tables with jquery by receiving json response from php

I want my output in following format. 我希望我的输出格式如下。 My design should be follows. 我的设计应如下。 产量

I want help to design the above method. 我想帮助设计上面的方法。 Please can anyone help me. 请任何人都可以帮助我。 I am storing rollno in student table and marks in marks table. 我存储rollnostudent表和marksmarks表。 Mark table contains a reference to student rollno . 标记表包含对student rollno的引用。

How can I send the json value to jquery ajax using php and assign the response to the page? 如何使用php将json值发送到jquery ajax并将响应分配给页面?

Or if you have any other method to do this. 或者,如果您有任何其他方法来执行此操作。 Please suggest that also. 请同意。 Thanks in advance. 提前致谢。

Try it like, 试试吧,

$(function(){
    $.ajax({
       url:'getStudMarks.php',
       data:{rollNo:'19GH24'},// get marks of student 19GH24 
       type:'POST',
       success:function(data){
          $('table tbody').html(data);
       }
    });
});

And in getStudMarks.php page return your data like, 并在getStudMarks.php页面返回您的数据,如,

<tr><td>C</td><td>90</td><td>98</td></tr>;

For multiple tables you needt to give table id like 对于多个表,您需要提供table id

<table id="table-19GH24">
    <thead>
       ....
    </thead>
    <tbody>....</tbody>
</table>

And in success callback use the rollno like, 并且success callback使用rollno类的,

$('#table-19GH24 tbody').html(data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM