从MySQL数据库中检索与jQuery,AJAX和PHP数据 [英] Retrieving Data with Jquery, AJAX, and PHP from a MySQL Database

查看:159
本文介绍了从MySQL数据库中检索与jQuery,AJAX和PHP数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何使用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

http://www.ryancoughlin.com / 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.

喜欢这里解释的:

http://openenergymonitor.org/emon/node/107

<一个href="http://www.electrictoolbox.com/json-data-jquery-php-mysql/">http://www.electrictoolbox.com/json-data-jquery-php-mysql/

这篇关于从MySQL数据库中检索与jQuery,AJAX和PHP数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆