我试图找出如何使用AJAX调用到PHP页面MySQL数据库检索数据。我一直跟着教程
I am trying to figure out how to retrieve data from a MySQL database using an AJAX call to a PHP page. I have been following this tutorial
www.ryancoughlin / 2008/11/04 /使用-的jQuery到提交表单/
但我无法弄清楚如何得到它发回JSON数据,这样我可以阅读。
But i cant figure out how to get it to send back json data so that i can read it.
现在,我有这样的事情:
Right now I have something like this:
$('h1').click(function() { $.ajax({ type:"POST", url: "ajax.php", data: "code="+ code, datatype: "xml", success: function() { $(xml).find('site').each(function(){ //do something }); }); });
我的PHP我想会是这样
My PHP i guess will be something like this
<?php include ("../../inc/config.inc.php"); // CLIENT INFORMATION $code = htmlspecialchars(trim($_POST['lname'])); $addClient = "select * from news where code=$code"; mysql_query($addClient) or die(mysql_error()); ?>本教程只展示了如何将数据插入一个表格,但我需要读取数据。任何人都可以点我在往好的方向发展?
This tutorial only shows how to insert data into a table but i need to read data. Can anyone point me in a good direction?
谢谢
克雷格
推荐答案这是没有什么不同。还是做你的东西在ajax.php获取数据,通常是我们做的。和发送响应你的货柜页面上。
It's nothing different. Just do your stuff for fetching data in ajax.php as usually we do. and send response in your container on page.
喜欢这里解释的:
openenergymonitor/emon/node/107
www.electrictoolbox/json-data-jquery-php-mysql/
更多推荐
从MySQL数据库中检索与jQuery,AJAX和PHP数据
发布评论