简体   繁体   English

XMLHttpRequest在一个页面上被阻止,但在另一页面上没有?

[英]XMLHttpRequest blocked on one page but not another?

I have two pages, both on the same domain. 我有两个页面,都在同一个域中。 Both are attempting to get an events feed from Google Calendar. 两者都试图从Google日历获取事件供稿。 One is successful, one is not. 一个成功,一个不成功。 The only difference is that one use jQuery's document.ready, and the other uses window.onload. 唯一的区别是,一个使用jQuery的document.ready,另一个使用window.onload。

Page that works: http://wwwtest.english.wisc.edu/calendar.htm 起作用的页面: http : //wwwtest.english.wisc.edu/calendar.htm

Page that doesn't work: http://wwwtest.english.wisc.edu/844.htm 无法使用的页面: http : //wwwtest.english.wisc.edu/844.htm

The second page is being generated by a CMS, so I don't have as much control over the script's loading order, thus I'm using window.onload to ensure the other scripts are loaded first. 第二页是由CMS生成的,因此我对脚本的加载顺序没有太多控制,因此我使用window.onload来确保首先加载其他脚本。

* Additional clarifications below * * 以下是其他说明 *

Yes, I've done debugging, here is the exact error: 是的,我已经完成调试,这是确切的错误:

XMLHttpRequest cannot load https://www.google.com/calendar/feeds/rhrab82ir5qgut1ddv7qj087c8%40group.ca …ar.google.com/public/basic?start=1356847200&end=1360476000&_=1358694509517. XMLHttpRequest无法加载https://www.google.com/calendar/feeds/rhrab82ir5qgut1ddv7qj087c8%40group.ca…ar.google.com / public / basic?start = 1356847200&end = 1360476000&_ = 1358694509517。 Origin http://wwwtest.english.wisc.edu is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许使用来源http://wwwtest.english.wisc.edu

But the confusing part for me is this: 但是令我困惑的部分是:

I copied the code from the page that works and only changed two things: 我从有效的页面复制了代码,仅更改了两件事:

1) I changed from using jQuery's document.ready to using window.onload 1)我从使用jQuery的document.ready更改为使用window.onload

2) I changed the jQuery selector 2)我改变了jQuery选择器

I may have found your issue with a quick debug in firebug. 我可能在firebug中发现了您的快速调试问题。 Your call 您的来电

https://www.google.com/calendar/feeds/rhrab82ir5qgut1ddv7qj087c8%40group.calendar.google.com/public/basic?start=1356850800&end=1360479600&_=1358632991615 is returning: XML Parsing Error: no element found Location: moz-nullprincipal:{627004d0-0e97-ca46-9ae8-767df4ae9d4f} Line Number 1, Column 1: https://www.google.com/calendar/feeds/rhrab82ir5qgut1ddv7qj087c8%40group.calendar.google.com/public/basic?start=1356850800&end=1360479600&_=1358632991615返回:XML解析错误:找不到元素位置:moz-nullprincipal :{627004d0-0e97-ca46-9ae8-767df4ae9d4f}第1行,第1列:

There is some interesting info located at Cross-domain Ajax call gets no element found Location: moz-nullprincipal and 跨域Ajax调用中有一些有趣的信息, 未找到任何元素。位置:moz-nullprincipal

jQuery Ajax call No element found issue jQuery Ajax调用找不到元素问题

XMLHttpRequest cannot load https://www.google.com/calendar/feeds/rhrab82ir5qgut1ddv7qj087c8%40group.ca …ar.google.com/public/basic?start=1356814800&end=1360443600&_=1358633133560. XMLHttpRequest无法加载https://www.google.com/calendar/feeds/rhrab82ir5qgut1ddv7qj087c8%40group.ca…ar.google.com / public / basic?start = 1356814800&end = 1360443600&_ = 1358633133560。 Origin http://wwwtest.english.wisc.edu is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许使用来源http://wwwtest.english.wisc.edu

I use Chrome for debugging such things. 我使用Chrome调试此类内容。 Ctrl+Shift+J for JavaScript console. Ctrl + Shift + J用于JavaScript控制台。

Apparently full calendar has a specific additional script that is needed to use Google calendar events. 显然,完整日历具有使用Google日历事件所需的特定其他脚本。

Info here: http://arshaw.com/fullcalendar/docs/google_calendar/ 此处的信息: http : //arshaw.com/fullcalendar/docs/google_calendar/

The first example has this script loaded, but the second did not. 第一个示例已加载此脚本,而第二个示例未加载。 After adding it the events load properly. 添加后,事件将正确加载。

第一个使用jsonp api,而第二个使用xml api,因此对同一来源策略适用。如果您可以更改第二个请求以使用jsonp api。

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

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