Php 如何使用.load()根据推荐人URL加载特定的内容ID

Php 如何使用.load()根据推荐人URL加载特定的内容ID,php,jquery,Php,Jquery,这里是我的代码示例,当用户单击链接时,它将加载一个特定的内容id,如果没有点击操作,它将显示默认的内容到#content div $(document).ready(function () { $.ajaxSetup({ cache: false }); $("a.view").live('click', function (e) { var id = $(this).data("id"); $('#content').lo

这里是我的代码示例,当用户单击链接时,它将加载一个特定的内容
id
,如果没有
点击
操作,它将显示
默认的
内容到
#content div

$(document).ready(function () {
    $.ajaxSetup({
        cache: false
    });
    $("a.view").live('click', function (e) {
        var id = $(this).data("id");
        $('#content').load("content.php?" + id);
        e.preventDefault();
    });
    $('#content').load("content.php");
});
问题,当用户使用
直接链接或键入url栏时,如何自动加载内容:示例
http://domain.com/content.php?id=5

因此,如果用户键入或使用直接链接,我希望脚本执行与
.live('click')
完全相同的操作,并加载
当前id
示例为
5


让我知道。

使用您的示例,您需要一个锚来绑定到:

<a href="#" data-id="5" class="view">Some Link</a>

但是,如果您正在寻找一个无缝(且SEO可接受)的内容页面,我会考虑使用hashbang语法:

以下是如何使用JavaScript获取
get
-参数:-您可以在加载时检查这些参数,如果它们已设置,然后决定做什么。也许您可以将click函数外包给一个命名函数,该函数接受一个参数,然后在设置GET参数或单击时调用它。您是否尝试过在查询字符串中命名id参数<代码>$('#content').load(“content.php?id=“+id”)
$(function(){
  // bind to current and future anchors with the "view" class applied
  $('a.view').live('click',function(){
    // grab the content and load it in to the container
    $('#container').load('content.php?id=' + $(this).data('id'));
    // return false so it doesn't follow the link
    return false;
  });

  // also load the default content (before any click event)
  $('#container').load('defaultContent.php');
});