Fancybox | Ajax request not working

此生再无相见时 提交于 2019-12-10 18:36:41

问题


I've been trying for hours to make fancybox to load a php file, with no success...

Here's the details:

You can visit the website having the problem here. Fancybox request is called when you click either "Παλαιά Δημοτικά Λουτρά" or "Αρχαίο Ωδείο", next to each image.

First, page's content is loaded through an ajax request. This page contains the link:

<a class="area_fancybox" href="http://www.mysite/fancy_areas.php?areasName=' . $the_area . '">' . $the_area . '</a>

Where $the_area variable is the parameter I want to pass to the php file that fancybox will load. Now when page's content has loaded, I add the fancybox code, like this.

jQuery('#diethnes_festival_2012').load('../../../diethnes_festival_2012.php', function() {
  jQuery("a.area_fancybox").fancybox();
});

When you click "area_fancybox" link, fancybox starts loading, but nothing happens...

Any help will be very appreciated.


回答1:


Fancybox ajax call requests from url starting with www while your link doesn't have this part. If you load your page with www. at the begining then the call works. This is due to the allow-control-access-policy of the browsers. Always use firebug or chrome developer tools to look for errors in console.




回答2:


It's a cross-domain issue (you're not allowed to load content from www.mysite from the domain mysite. You'll notice that if you visit the site with www in the URL, then it works as-is: http://www.mysite/events-pc/pc-festival/1610-diethnes-festival-patras-2012.html

I recommend using a relative path in the href, which should make your code work for both cases:

<a class="area_fancybox" href="/fancy_areas.php?areasName=Παλαιά Δημοτικά Λουτρά">Παλαιά Δημοτικά Λουτρά</a>

Btw, I recommend checking out Firebug if you haven't already-- it's really helpful for debugging this kind of thing. If you're using Chrome, just hit ctrl-shift-J.



来源:https://stackoverflow.com/questions/10971670/fancybox-ajax-request-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!