简体   繁体   English

Google Chrome-失败的GET ajax请求

[英]Google Chrome - Failed GET ajax request

I am developing a website which loads html from a template page then loads content from XML. 我正在开发一个网站,该网站从模板页面加载html,然后从XML加载内容。 for instance these are called in the document.ready function 例如,这些在document.ready函数中调用

$.ajax({
                type : "GET",
                url : "template.html",
                dataType : "html",
                success : function(html) {
                    var ndoc = document.createElement('html');
                    ndoc.innerHTML = html;
                    page = $('body', ndoc);
                    $('body').html(page.html());

                    $.ajax({
                        type : "GET",
                        url : "XML/content.xml",
                        dataType : "xml",
                        success : function(xml) {
                            page = $(xml).find('chisiamo').find('dialogue')[0];

                            setupPage(page);
                        }
                    });

                }
            });

This works well in Firefox and Safari. 这在Firefox和Safari中效果很好。 But in Chrome i get a 'Origin null is not allowed by Access-Control-Allow-Origin' when it tries to load template.html. 但是在Chrome浏览器中,当我尝试加载template.html时,出现“访问控制不允许允许来源为null”的问题。 How can I solve this problem? 我怎么解决这个问题? thank you very much. 非常感谢你。

尝试使用以下参数启动Google Chrome:

google-chrome --disable-web-security --allow-file-access-from-files

You should be able to create a Chrome Web App and set the permissions in the manifest to allow it access to read files from the file:// scheme. 您应该能够创建Chrome Web App并在清单中设置权限,以允许其访问从file://方案读取文件。

http://code.google.com/chrome/extensions/manifest.html http://code.google.com/chrome/extensions/manifest.html

You have to add permissions to the page you are requesting in the manifest. 您必须在清单中请求的页面上添加权限。 Also try using $.getJSON instead ;) 也尝试改用$ .getJSON;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM