dsw7547 2010-01-31 17:24
浏览 75

如何让超链接将2个数组值传递给另一个脚本并打印该脚本的页面?

I have a list of names (1-15 rows) I display from an array. I want the administrator to select the correct name from the list by clicking on the hypertext called "link." The record id is in the array and I want that passed to the called script.

I found this javascript that works except that I want the linkur.php page to print (with its information messages). I know it doesn't print because of the void(0) but can not figure the correct method needed.

<a href="javascript:void(0);" onclick='$.get("linkur.php",{ rid: "<?php echo $k['id']; ?>", uid: "<?php echo $uid; ?>", } ,function(data){ $("#link<?php echo $k['id']; ?>").html(data); });'>Link</a>

Also, is it possible to do the hyperlink with pure HTML? The hyperlink is straight forward except for passing the array values.

Thanks for any ideas.

Carl

  • 写回答

2条回答 默认 最新

  • douxian1923 2010-01-31 17:31
    关注

    I'm a bit confused by your request. You don't mention needing an asynchronous request, yet that is what your code is doing using the jQuery library. If you don't need an asynchronous request, and want to see the end-page, you just build a regular link:

    <a href="linkur.php?rid=<?php print $rid; ?>&uid=<?php print $uid; ?>">Link</a>
    

    This would be rendered on the page with solid values rather than variables:

    <a href="linkur.php?rid=123&uid=281">Link</a>
    

    Once you clicked the link, you would pass rid=123 and uid=281 to the end-script, seeing its output on the screen.

    Properly Adding some Asynch'ness

    If you need to load this data asynchronously, there is only a small addition to the code. Keep the original link that we just referenced above, but add a class to it:

    <a href="linkur.php?rid=123&uid=281" class="loadme">Link</a>
    

    Now with jQuery we can incercept these requests and load up their HTML elsewhere:

    $(function(){
      // Intercept the click event of our links
      $(".loadme").click(function(e){
        // Prevent them from leaving the page
        e.preventDefault();
        // Fire off a request for their content
        $.get($(this).attr("href"), function(data) {
          // Load their content into a container on our page
          $("#content-viewer").html(data);
        }, "html");
      });
    });
    

    Note that I referenced a #content-viewer. You would need to have this on your page someplace:

    <div id="content-viewer">I will show the content .loadme links!</div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)