Chrome扩展Ajax请求

时间:2011-05-15 06:13:06

标签: jquery ajax json google-chrome-extension

我是一名新手,正在开发一个google-chrome扩展程序,需要向服务器发出jquery ajax请求,加载一些html文档。我的服务器是Apache,使用 XAMPP 1.7.3 在localhost上运行。 jquery是 jquery-1.6.1.js

当我使用像http://localhost/Chrome/popup.html这样的标准浏览器加载它时,jquery ajax可以工作。它加载了html文档funtionaly。但是,问题是当我通过Google Chrome (Google Chrome 11)扩展程序开发人员模式中的“加载解压扩展程序”打开我的扩展程序时。 html文档无法加载

任何人都可以帮助解决我的问题吗?

这是我的代码:

的manifest.json

        {
        "name": "Nyu Extension",
        "version": "1.0",
        "description": "My First Extension",
        "permissions" : ["http://localhost/", "http://*/*"],
        "browser_action": {
        "default_icon": "N.png",
        "popup": "popup.html"
        }
        }

popup.html

        ...
        function activeTab(tab)
        {   
            document.getElementById("tab1").className = "";
            document.getElementById("tab"+tab).className = "active";           
            if(tab == 1)
            {
                $.ajax({
                    url: "ssc/contentpage1.txt",
                    success: function(data) {
                        $('#content').html(data);
                    }
                });
            }
        }
        ...

如果有什么不妥,请告诉我..

1 个答案:

答案 0 :(得分:8)

您应该在$ .ajax调用中指定绝对(完整)网址(即http://localhost/Chrome/ssc/contentpage1.txt)。