搜索数据库,然后使用jQuery和AJAX将返回的查询加载到页面上 [英] Search the database and load the returned query onto the page using jQuery and AJAX

查看:74
本文介绍了搜索数据库,然后使用jQuery和AJAX将返回的查询加载到页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在某个页面上做一些工作,我想根据用户正在寻找的内容搜索数据库,然后在同一页面上返回结果.我知道如何使用jQuery使事物从页面中消失,但是我想知道如何使用AJAX将其添加到页面中.

I am doing some work on a page where I want to search the database based on what the user is looking for and then give back the results on the same page. I know how to make things disappear from a page using jQuery, but I would like to know how to append them to the page using AJAX.

我要问的简短内容是,我想查询数据库,并在不重新加载页面的情况下将结果弹出到网站上.

The short of what I'm asking, I want to query the DB, and have the results pop up on the website without reloading the page.

下面的答案并不能真正回答我的问题,因此我将通过示例给出更详细的问题.

Well the answer below is not really answering my question so I will give a more detailed question with an example.

    <input type="textbox" id="name" name="name" />
    <input type="button" id="search" name="search" value="Search the Database" /> <br/><br/>
    <label class="userinfo">First Name: </label><input type="text" class="userinfo" id="first" name="first" /> <br/>
    <label class="userinfo">Last Name: </label><input type="text" class="userinfo" id="last" name="last" /> <br/>
    <label class="userinfo">Username: </label><input type="text" class="userinfo" id="uname" name="uname" /> <br/>
    <label class="userinfo">E-Mail: </label><input type="text" class="userinfo" id="email" name="email" /> <br/>
    <label class="userinfo">Admin Status: </label><input type="text" class="userinfo" id="admin" name="admin" /> <br/>

发生的事情是,我基于第一个文本框搜索数据库,按下搜索按钮时将发生AJAX,它将转到另一页并在数据库上进行查询.如何将这些结果返回到原始页面以填写下面的文本框?在单击搜索按钮之前,将隐藏下面的texbox.因此,我需要发送一个变量并返回多个变量.这对您有帮助吗?

What happens is that I search the database based on the first textbox, the AJAX will happen when the search button is pressed, it will go to another page and do the query on the db. How do I get those results back to the original page to fill out the textboxes below? The texboxes below are hidden until the search button is clicked. So I need to send one variable and get multiple variables back. Does that help you help me more?

推荐答案

以下是ajax + html附加示例:

Here's a sample of ajax + html append:

   <html>
        <head>
        <script type="text/javascript">

        $(function() {

        $('.go-right').click(function(){

            $.ajax({

                        type: "POST",
                        url: "process_thumbs.html",
                        data:   "showposts=25",
                        success: function(html){
                            $("#output").html(html);
                        }

            });  
        });

            });

        </script>

        </head>
        <body >


        <div id="output"></div>

        <a class="go-right">RIGHT</a>

        </body>
        </html>

当然"process_thumbs.html"是返回查询结果的动态页面.

of course "process_thumbs.html" is a dynamic page returning the results of the query.

这篇关于搜索数据库,然后使用jQuery和AJAX将返回的查询加载到页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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