weixin_33698823 2013-04-16 12:33 采纳率: 0%
浏览 21

加载配置文件onclick搜索

I have been creating an ajax search. I have been wondering how to load the user's profile when clicked on the search results using ajax. I tried assigning the ID of user from database to div using the following code so that I can have an ajax to load the profile:-

echo "<div id='$id'><img src='$img' /></div>

I wanted to set an ajax to load profile page and from the profile page, there will be a query to search database for the user. The variable ($img/$id) seems to work on the img tag but did not work on div id. So, I am stuck wondering how facebook and google+. I tried googling but, no such results were found.

To put it in simpler words, I don't know how to assign a variable (to id or any other place an ajax can get the value from) so that ajax can load it and then post it to the profile.php so that profile.php can query the database and show the results.

edit: Since some of you might misunderstand, I don't have a problem with assigning the image, I have problem assigning an id as a variable so that I can auto assign it using database .

  • 写回答

1条回答 默认 最新

  • weixin_33670786 2013-04-16 12:44
    关注

    If you want to load something based on a value, you can try it with the data-* attributes in html. For example:
    <div class="user-link" data-userid="<?= $user_id; ?>"><img src="..." /></div>
    can be retrieved as:

    $('.user-link').click(function() { 
      console.log($(this).data('userid'));
    });
    

    edit: http://api.jquery.com/data/

    In your case, you could the post in the on-click.

    edit 2: I have made the userid a php variable as requested by a deleted comment.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配