dongshanfan1941 2015-04-22 13:37
浏览 68

如何在单击链接时向页面添加内容,然后使用jQuery重定向到该页面?

When a certain image is clicked I want to add some content to a different page using jQuery. I have a generic page called product.php and on this page the content to be added depends on which image it is clicked on the home page (home.php). On product.php I am trying to add the content on a div with the id of #product.

But when the image is clicked it redirects to the unmodified page of product.php. Is there a way to redirect to the product.php page after the wanted content is loaded?

$('.product img').click(function () {
    // it gives the right index         
    var index = $( ".product img" ).index( this ); 
    // it works well
    var myProduct = 'snippet-product'+ (index + 1)+'.php'; 
    $( "#product" ).load( myProduct ); 
    // it redirects  to the 'product.php' without the new content
    window.location.href = 'product.php'; 
    return false;   
});
  • 写回答

2条回答 默认 最新

  • dongshun1884 2015-04-22 13:55
    关注

    I don't know if i understand your question but you need to redirect with a location like: window.location.href = 'product.php?product=' + index; as @lharby said, and then change your PHP code catching the $_REQUEST["product"] and make a switch or an if to show content based on $_REQUEST["product"] value.


    Your "initial question" was:

    • Step 1. Load content to a page.
    • Step 2. Go to location product.php.

    If you reload the page (or change the location), all your content loaded with jQuery disappears. Do you know what i mean?

    I really don't know what you want.

    Do you want only to change the URL but don't reload the page? Please explain a bit more what you want to acomplish.

    Sorry for my English...

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)