【发布时间】:2012-11-25 19:52:46
【问题描述】:
我正在创建一个读取特定文件的 AJAX 脚本,该文件的名称由 GET var 标识。 index.php中脚本的开头是:
var expFile = '<?php echo $_GET['text_name']; ?>';
$(document).ready(function () {
$.ajax({
url: expFile+'.xml',
type: 'get',
dataType: 'xml',
success: function (data, textStatus) {
// Parses the content, which is escaped into a "text" tag in the xml, and puts it
//into an html div with a "content" class"
var content = decodeURIComponent($(data).find('text').text());
$('.content').html(content);
}
});
});
一切顺利。文件被读取并且东西显示正确。 与 index.php 文件位于同一文件夹中的 XML 文件是直接从 AJAX 读取的。
现在我正在使用 mod_rewrite 以使 URL 对 SEO 友好。
当我输入脏 URL (http://www.mysite.com/index.php?text_name=name-of-the-file-to-read) 就可以了。
但是当我输入重写后的网址(即http://www.mysite.com/lyrics/name-of-the-file-to-read)时,内容并没有显示出来。
我知道 AJAX 是客户端,而 mod_rewrite 是服务器端,但我不知道如何从 $.ajax 的“url”参数访问父文件夹(实际上不存在)或像url: 'http://...' 这样的绝对链接(但它违反了同源政策)。
请帮帮我!!!
【问题讨论】: