0

I'm using JQuery UI to create a tab, and I want to the contents of my php file to be entered into this tab. I start by creating a tab, and then selecting it.

function createTab2() {
       //create a tab
       $("#tabs").tabs("add","#tabs-2","Second Tab");
       $("#tabs-2").css("display","block");   
       $('#tabs').tabs('select', "#tabs-2");        
       $.get('tab2.php', function(data) {
            $('.result').html(data);
            alert('Load was performed.');
        });
}

I tried using the JQuery .get function to return the data and it works fine as an alert appears. However, the contents are not entered into the tab - I just see them listed in my Javascript console.

How can I make the contents of the php file appear in this tab?

6
  • When you say contents do you mean raw data or data formatted in html ? Commented Apr 2, 2012 at 19:12
  • 2
    in jqueryui.com, there is a demo to load content via ajax. check it out jqueryui.com/demos/tabs/#ajax Commented Apr 2, 2012 at 19:13
  • Do you only have one .result div? Commented Apr 2, 2012 at 19:20
  • @DG3 Nice - I missed that. Do you know how I combine that with the creation of a tab? I can see how I use it in the loading of an existing tab. There are no divs within the tab after I create it (another problem that I did not notice). Commented Apr 2, 2012 at 19:21
  • jqueryui.com/demos/tabs/#manipulation. Commented Apr 2, 2012 at 19:26

1 Answer 1

1

In your markup for tab 2 you need add an href to the source html.

<div id="tabs">
 <ul>
     <li><a ><span>Content 1</span></a></li>
     <li><a href="tab2.php"><span id="tabs-2">Content 2</span></a></li>
     <li><a ><span>Content 3</span></a></li>
 </ul>
</div>

or you can try load the tab directly.

$("#tabs-2").load('tab2.php');

source

Sign up to request clarification or add additional context in comments.

3 Comments

wow! $("#tabs-2").load('tab2.php'); works. Unfortunately it does not seem to pick up on the css styles.
it will only pick up styles that are included in the calling page.
The styles are picked up if I have a static page. If I replace this tab 2 with php, the styles are no longer applied.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.