谷歌的#! Ajax 实现 - 不使用 jQuery

发布于 2024-11-29 19:37:45 字数 1528 浏览 2 评论 0原文

好吧,我正用头撞桌子,显然错过了一些简单的事情。

尝试让我的 Ajax 页面可供 google 抓取。但是,它不起作用。

顺便说一句,我所说的内容中有链接并用作主要导航。

    <script type="text/javascript">
      // Test script
     $.ajaxSetup({
    type: "GET",  
    url: "UpdateResults7.php#!",   
    /*dataType: "text/html",  eliminated moveing from jq 1.4.1 to 1.5*/
    beforeSend:  function(){$("#txtResult").html("Pending"); },
    success: function(html){       $("#txtResult").html(html);     }
    });  // close $.ajaxSetup

    function dynamic_Select( state)  
    {  
    var myData = {pass_type: "<?php echo $pass_type ?>", pass_state: state};
    //$.post("setSession.php", {pass_state: state });
    $.ajax({  
            data: myData });  // close $.ajax
    } // close dynamic_Select   
    </script>

提前致谢!


好的,谢谢你的帮助。这就是我的立场: 1.) 我的页面已使用 #! 实现并且 AJAX 工作正常 2.) 我进入 Firefox 并复制并保存该文件的 HTML 版本 3.) 我在 php 文件顶部放置了一些脚本来检测“?_escaped_fragment_=”并重定向到 html 文件。

但是,当我检查 Google 的 fetchbot 时,它不会显示任何 AJAX 生成的内容。我什至将“?_escaped_fragment_=”加载到地址栏中,以确认它加载了正确的 html 副本,确实如此。

这是页面顶部的代码:

    if (isset($_GET['_escaped_fragment_'])){
header(sprintf("Location: solidgreen-partners.html", $insertGoTo));
$path = $_SERVER['PHP_SELF'];
//generateStaticPHP($path);
    }

最后几行不起作用。我试图按照 http:// 的描述即时生成 HTML 快照code.google.com/web/ajaxcrawling/docs/html-snapshot.html

再次感谢您的帮助!

OK, I'm banging my head against the desk and obviously missing something simple.

Trying to make my Ajax pages crawlable for google. However, it isn't working.

BTW, the content I call has links in it and serve as primary navigation.

    <script type="text/javascript">
      // Test script
     $.ajaxSetup({
    type: "GET",  
    url: "UpdateResults7.php#!",   
    /*dataType: "text/html",  eliminated moveing from jq 1.4.1 to 1.5*/
    beforeSend:  function(){$("#txtResult").html("Pending"); },
    success: function(html){       $("#txtResult").html(html);     }
    });  // close $.ajaxSetup

    function dynamic_Select( state)  
    {  
    var myData = {pass_type: "<?php echo $pass_type ?>", pass_state: state};
    //$.post("setSession.php", {pass_state: state });
    $.ajax({  
            data: myData });  // close $.ajax
    } // close dynamic_Select   
    </script>

Thanks in advance!


OK, Thanks for your help. Here is where I stand:
1.) My pages have been implemented with #! and the AJAX is working fine
2.) I went into firefox and copied and saved a HTML version of the file
3.) I put some script at the top of my php file to detect "?_escaped_fragment_=" and redirect to the html file.

However, when I check on Google's fetchbot, it doesn't display any of the AJAX generated content. I've even loaded the "?_escaped_fragment_=" into the address bar to confirm it loads the proper html copy, and indeed it does.

Here is the code at the top of the page:

    if (isset($_GET['_escaped_fragment_'])){
header(sprintf("Location: solidgreen-partners.html", $insertGoTo));
$path = $_SERVER['PHP_SELF'];
//generateStaticPHP($path);
    }

The last couple lines aren't working. I was trying to generate the HTML snapshot on the fly as described http://code.google.com/web/ajaxcrawling/docs/html-snapshot.html

Thanks again for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场信仰旅途 2024-12-06 19:37:45

看来您对于如何实现这一点没有正确的想法。

您网站上面向公众(或面向搜索引擎)的链接应在适当的情况下使用 hashbang 语法 (#!)。这向 Google(或许还有其他搜索引擎)表明您的网站可以 AJAX 抓取。然后,Googlebot 将使用名为 _escaped_fragment_ 的 GET 参数实际请求这些页面。您的应用程序必须接受此参数并利用它向 Googlebot 返回 HTML 快照。

因此,您网站上的 URL(例如:)

http://mydomain.com/mypage.html#!somevar=somevalue

实际上会被 Googlebot 请求为:

http://mydomain.com/mypage.html?_escaped_fragment_=somevar=somevalue

然后,您的应用程序会采用 _escaped_fragment_ 的值解析出参数,进行构建,然后返回相应的 HTML。

然而,这些都不适用于您在站点内部进行的实际 AJAX 调用。这是你的问题所在。

请参阅:http://code.google.com/web/ajaxcrawling/docs /getting-started.html 了解更多信息。

It doesn't look like you have the right idea about how this is supposed to be implemented.

The public-facing (or search-engine-facing) links on your site should employ the hashbang syntax (#!) where appropriate. This indicates to Google (and perhaps other search engines) that your site is AJAX-crawlable. Googlebot will then actually request those pages using a GET parameter called _escaped_fragment_. Your application must accept this parameter and utilize it to return an HTML snapshot to Googlebot.

So an URL on your site such as:

http://mydomain.com/mypage.html#!somevar=somevalue

will actually be requested by Googlebot as:

http://mydomain.com/mypage.html?_escaped_fragment_=somevar=somevalue

Your app then takes that the value of _escaped_fragment_ parses out the parameters, builds, and then returns the appropriate HTML.

None of this however applies to the actual AJAX calls you make internally on your site. Which is your problem here.

See: http://code.google.com/web/ajaxcrawling/docs/getting-started.html for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文