简体   繁体   中英

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. One is successful, one is not. The only difference is that one use jQuery's document.ready, and the other uses window.onload.

Page that works: http://wwwtest.english.wisc.edu/calendar.htm

Page that doesn't work: 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.

* 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. Origin http://wwwtest.english.wisc.edu is not allowed by Access-Control-Allow-Origin.

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

2) I changed the jQuery selector

I may have found your issue with a quick debug in 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:

There is some interesting info located at Cross-domain Ajax call gets no element found Location: moz-nullprincipal and

jQuery Ajax call No element found issue

XMLHttpRequest cannot load 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.

I use Chrome for debugging such things. Ctrl+Shift+J for JavaScript console.

Apparently full calendar has a specific additional script that is needed to use Google calendar events.

Info here: 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。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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