关于ajax操作数据库后的数据处理问题
在做一个页面,类似刷微博时拉到最下面可以选择“加载更多”,现在通过ajax实现了对数据库的操作
function ajax() { var page=document.getElementById("pageNum").value++; //先声明一个异步请求对象 var xmlHttpReg = null; if (window.ActiveXObject) {//如果是IE xmlHttpReg = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttpReg = new XMLHttpRequest(); //实例化一个xmlHttpReg } //如果实例化成功,就调用open()方法,就开始准备向服务器发送请求 if (xmlHttpReg != null) { xmlHttpReg.open("get", "pro.php?index="+page, true); xmlHttpReg.send(null); xmlHttpReg.onreadystatechange = doResult; //设置回调函数 } //回调函数 //一旦readyState的值改变,将会调用这个函数,readyState=4表示完成相应 //设定函数doResult() function doResult() { if (xmlHttpReg.readyState == 4) {//4代表执行完成 if (xmlHttpReg.status == 200) {//200代表执行成功 //将xmlHttpReg.responseText的值赋给ID为resText的元素 document.getElementById("resText").innerHTML = xmlHttpReg.responseText; } } } }
后台数据库是php实现的,语句是
…………$sql="select * from tb_test limit ".$index*4;$result = mysql_query($sql, $con);
写到这儿不知道该怎么办了
通常情况下
使用while ($row=mysql_fetch_array($result)) {
……
}
就可以了,现在不知道改怎么输出,而且我的前台页面中,这些更新的数据是在一个table中
回复讨论(解决方案)
while ($row=mysql_fetch_array($result)) {
……
}
一样的在这个里面进行循环,但是此时可以加上tr等table下的标签然后组合成数组后,再转换成你要求的输出格式进行输出到结果就可以了。
将从数据库获取的数据(一般是数组),echo json_encode($res);
前台js用
var res=xmlHttpReg.responseText;
res=eval('('+res+')');
解出来
res['键名'],就可以获取对应的键值
将从数据库获取的数据(一般是数组),echo json_encode($res);
前台js用
var res=xmlHttpReg.responseText;
res=eval('('+res+')');
解出来
res['键名'],就可以获取对应的键值
然后在JS里面输出那些表格吗?
你可以像1楼说的,在php里面组织好表格(就是一个字符串),然后直接echo,js获取后不用解,直接插入到要显示的位置
因为我觉得js循环数据组织html比较麻烦(一般情况下),还不如php组织好直接输出

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

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.

Last week, amid the internal wave of resignations and external criticism, OpenAI was plagued by internal and external troubles: - The infringement of the widow sister sparked global heated discussions - Employees signing "overlord clauses" were exposed one after another - Netizens listed Ultraman's "seven deadly sins" Rumors refuting: According to leaked information and documents obtained by Vox, OpenAI’s senior leadership, including Altman, was well aware of these equity recovery provisions and signed off on them. In addition, there is a serious and urgent issue facing OpenAI - AI safety. The recent departures of five security-related employees, including two of its most prominent employees, and the dissolution of the "Super Alignment" team have once again put OpenAI's security issues in the spotlight. Fortune magazine reported that OpenA

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

70B model, 1000 tokens can be generated in seconds, which translates into nearly 4000 characters! The researchers fine-tuned Llama3 and introduced an acceleration algorithm. Compared with the native version, the speed is 13 times faster! Not only is it fast, its performance on code rewriting tasks even surpasses GPT-4o. This achievement comes from anysphere, the team behind the popular AI programming artifact Cursor, and OpenAI also participated in the investment. You must know that on Groq, a well-known fast inference acceleration framework, the inference speed of 70BLlama3 is only more than 300 tokens per second. With the speed of Cursor, it can be said that it achieves near-instant complete code file editing. Some people call it a good guy, if you put Curs

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,

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.
