谷歌的#! Ajax 实现 - 不使用 jQuery
好吧,我正用头撞桌子,显然错过了一些简单的事情。
尝试让我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您对于如何实现这一点没有正确的想法。
您网站上面向公众(或面向搜索引擎)的链接应在适当的情况下使用 hashbang 语法 (#!)。这向 Google(或许还有其他搜索引擎)表明您的网站可以 AJAX 抓取。然后,Googlebot 将使用名为
_escaped_fragment_
的 GET 参数实际请求这些页面。您的应用程序必须接受此参数并利用它向 Googlebot 返回 HTML 快照。因此,您网站上的 URL(例如:)
实际上会被 Googlebot 请求为:
然后,您的应用程序会采用
_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:
will actually be requested by Googlebot as:
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.