How to load Ajax content into current colorbox window?

Source: Internet
Author: User

I'm searching for the answer for three days in a row already. the matter is that I have a page, links on which shocould load colorbox with Ajax content that in its turn contains links that shocould be loaded in the same colorbox modal window. so far I managed to make it work (partially) by this:

 
<SCRIPT type = "text/JavaScript">$ (Document). Ready (Function() {$ ("A [rel = 'open _ Ajax ']"). Live ('click ',Function() {$. Colorbox ({href: $ (This). ATTR ('href')});Return False;});});</SCRIPT>

It loads a colorbox window, if I click on a link, but in this window, if I click on its links, it opens another colorbox window. and I want the content to be loaded within the current one. will appreciate any thoughts. thanx!

P.s. Links in the main window:

 
<A Title = "client details" rel = "open_ajax" href = "http: // localhost/client/details/123"> client details... </a>

And links in the colorbox are all the same (it is simply pagination ):

 
<A rel = "open_ajax" href = "http: // localhost/client/details/123/1"> 1 </a> <a rel = "open_ajax" href = "http: // localhost/client/details/123/2 "> 2 </a> <a rel =" open_ajax "href =" http: // localhost/client/details/123/3 "> 3 </a> <a rel =" open_ajax "href =" http: // localhost/client/details/123/4 "> 4 </a> <a rel =" open_ajax "href =" http: // localhost/client/details/123/5 "> 5 </a>
1 answer

Youu wowould need to load the content into the same colorbox rather than opening a new instance. I wocould start by making sure that the event handler context to open the colorbox was exclusive and not hooked onto the 'open _ Ajax 'elements in the colorbox.

Something like this:

 
<SCRIPT type = "text/JavaScript">$ (Document). Ready (Function() {$ ("A [rel = 'open _ Ajax ']: Not (# colorbox A [rel = 'open _ Ajax'])"). Live ('click ',Function() {$. Colorbox ({href: $ (This). ATTR ('href')});Return False;});});</SCRIPT>

If the above does not work try making the selector more specific/Unique.

Then Ajax in the new content directly into the colorbox you already have open.

Something like this:

$ ('# Cboxloadedcontent A [rel = "open_ajax"]'). Live ('click ', Function  (E ){  //  Prevent default behaviour  E. preventdefault ();  VaR Url = $ ( This ). ATTR ('href' ); $. Ajax ({type: 'Get' , URL: URL, datatype: 'Html', Cache:  True  , Beforesend:  Function  () {$ ( '# Cboxloadedcontent' ). Empty (); $ ( '# Cboxloadinggraphic' ). Show () ;}, complete:  Function  () {$ ( '# Cboxloadinggraphic' ). Hide () ;}, success:  Function  (Data) {$ ( '# Cboxloadedcontent'). Append (data );}});}); 

Http://stackoverflow.com/questions/5273311/how-to-load-ajax-content-into-current-colorbox-window

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.