使用jQuery单击链接时加载最新数据 [英] load revelant data when clicking on link using jQuery

查看:83
本文介绍了使用jQuery单击链接时加载最新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试为我的网站制作地址簿,当时我正在考虑有两个窗格.左边的一个具有联系人名称,右边的​​一个具有联系人详细信息.

Hey, I'm trying to make an Address book for my site and I was thinking of having two panes. The one on the left to have Contact names, and the one on the right to have the contact details.

我可以使用while循环加载联系人"窗格以循环查询,但是当时我想我真的不知道当用户单击特定联系人姓名时如何加载该联系人的详细信息.

I can get the Contact pane loaded up using a while loop to cycle through my query, but then I was thinking that I really had no Idea how to load the details of that contact when the user clicks on a specific contact name.

我将如何解决这个问题?

How would I be able to approach this problem?

推荐答案

如果您有类似的东西:

<div id="contactNamesPane">
 <ul>
    <li><a href="#" class="names" id="johnDoe">Doe, John</a></li>
 </ul>
</div>

<div id="contactDetailsPane">
</div>

$('contactNamesPane a.names').click(
   var thisContactId = $(this).attr('id');
   $('contactDetailsPane')
        .load('http://path/to/script.php?contactId=' + thisContactId + ' #' + thisContactId);
);

假设您有一个php脚本来生成联系人详细信息(位于http://path/to/script.php,并且此脚本可以使用GET变量以显示特定的个人.

This has the assumptions that you have a php script to generate the contact details (located at http://path/to/script.php and this script can take a GET variable in order to show the particular individual.

它还假定此数据将被放置在一个ID等于联系人姓名的元素内.

It also assumes that this data will be placed inside an element of an id equal to the contact's name.

一个模糊连贯的演示在我的服务器上发布: http://davidrhysthomas.co.uk/so/loadDemo.html

A vaguely coherent demo's posted on my server at: http://davidrhysthomas.co.uk/so/loadDemo.html

这篇关于使用jQuery单击链接时加载最新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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