


jquery implementation class that obtains information from the background through AJAX and displays it on the table
jquery uses AJAX to obtain information from the background and display it on the form. The implementation class is written separately, so that programmers do not need to write code every time and can save a lot of time. Friends who are interested should take a look.
In the last article, I introduced you to JQuery using AJAX to obtain information from the background, display it on the table, and support row selection. Now, take some time to deal with it, so that you don’t need to write code every time. It can save a lot of time. Please see below for details:
The specific code is as follows:
//获取数据并显示数据表格 function GetTableData(tableId,ChlickEvent) { var table = $(tableId); var url=table.data('url'); $.ajax({ url: url, type: 'post', dataType: 'json', }) .done(function (json) { var fileds = new Array(); table.children('thead').children('tr').children('th').each(function (index, el) { var field = $(this).data('field'); fileds[index] = field; }); var tbody = ''; $.each(json, function (index, el) { var tr = "<tr>"; $.each(fileds, function (i, el) { if (fileds[i]) { tr += '<td>' + formatJsonData(json[index][fileds[i]]) + '</td>'; } }); tr += "</tr>"; tbody += tr; }); table.children('tbody').append(tbody); if (ChlickEvent) {//如果需要支持行选中事件 table.children('tbody').addClass('sel'); table.children('tbody.sel').children('tr').click(function (event) { $(this).siblings('tr').removeClass('active');//删除其他行的选中效果 $(this).addClass('active');//增加选中效果 ChlickEvent($(this).children('td:eq(0)').text());//新增点击事件 }); } }).fail(function () { alert("Err"); }); } //格式化JSON数据,比如日期 function formatJsonData(jsondata){ if(jsondata==null){ return '无数据'; } else if(/\/Date\(\d+\)/.exec(jsondata)){ var date = new Date(parseInt(jsondata.replace("/Date(", "").replace(")/", ""), 10)); return date.toLocaleString(); } return jsondata; }
It is very simple to write and has few functions, but it is enough for my own use for the time being. Meet simple needs.
HTML code must be in the following format. JSON data must be obtained through POST. The acquisition address must be written in the data-url, and the data column name must be written in the data-field.
Support click events.
Usage:
<table id="RoleGroupTable" class="table" data-url="@Url.Action("GetRoleGroups", "Account")"> <thead> <tr> <th data-field="ID">ID</th> <th data-field="Name">名称</th> <th data-field="Remark">简介</th> </tr> </thead> <tbody></tbody> </table> <script> jQuery(document).ready(function ($) { GetTableData('#RoleGroupTable', function (id) { alert(id) }); }); </script>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
JQuery Ajax dynamically generates Table tables
A brief analysis of the use of Ajax in Asp.net MVC
Realizing mobile phone positioning based on h5 ajax
The above is the detailed content of jquery implementation class that obtains information from the background through AJAX and displays it on the table. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

Although the general operations of domestic mobile phones are very similar, there are still some differences in some details. For example, different mobile phone models and manufacturers may have different dual-SIM installation methods. Erzhenwo 12Pro, a new mobile phone, also supports dual-SIM dual standby, but how should dual-SIM be installed on this phone? How to install dual SIM on Realme 12Pro? Remember to turn off your phone before installation. Step 1: Find the SIM card tray: Find the SIM card tray of the phone. Usually, in the Realme 12 Pro, the SIM card tray is located on the side or top of the phone. Step 2: Insert the first SIM card. Use a dedicated SIM card pin or a small object to insert it into the slot in the SIM card tray. Then, carefully insert the first SIM card.

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

Ajax (Asynchronous JavaScript and XML) allows adding dynamic content without reloading the page. Using PHP and Ajax, you can dynamically load a product list: HTML creates a page with a container element, and the Ajax request adds the data to that element after loading it. JavaScript uses Ajax to send a request to the server through XMLHttpRequest to obtain product data in JSON format from the server. PHP uses MySQL to query product data from the database and encode it into JSON format. JavaScript parses the JSON data and displays it in the page container. Clicking the button triggers an Ajax request to load the product list.

Many players want to know how to obtain fake future crystal coins. There are actually four different methods, including purchasing gift packages, completing tasks, producing goods, developing land, etc. Players can choose different ways to earn crystal coins according to their needs. The specific content is as follows: Get up and take a look at this guide on how to obtain fake future crystal coins. Fake Future Guide: How to get Fake Future Crystal Coins 1. Purchase the gift package mall to purchase the crystal coin gift package. 2. Obtained by completing tasks and completing main and side tasks. 3. Produce goods. Produce goods in your home to obtain crystal coins. 4. Developing land can also be obtained by developing land, but the reward is one-time.
