jQuery ajax call incorrectly nesting php generated html

I'm using jQuery to hijack a link pointing to a php file. This php file is mostly html, but calls two php functions that each use a for loop to output html. The problem I'm running into is that the ajax call is incorrectly nesting the html generated by the php for loop.

Including the php file directly onto the page works fine, but when trying to grab it via ajax the html content of each sequential pass through the loop is inserted inside the previously generated html. For example:

<div>Content1</div>
<div>Content2</div>
<div>Content3</div>

becomes:

<div>Content1<div>Content2<div>Content3</div></div></div>

This is the relevant code for the php file:

<div class="publishedPosts">
  <h3>Published</h3>
  <?php displayPublishedBlogPosts(); ?>
</div>
<div class="verticalDivider"></div>
<div class="draftPosts">
  <h3>Saved Drafts</h3>
  <?php displayBlogPostDrafts(); ?>
</div>

And this is the jQuery code:

function adminPanelTabs() {
  $('#adminPanelTabs ul li a').click(function(e) {
    $('#adminPanelTabs ul li a.current').removeClass('current');
    $(this).addClass('current');
    $('#adminPanelContent').load($(this).attr('href'));
    e.preventDefault();
  });
}

Would appreciate any input or suggestions on how to fix this.

Answers


Go figure - spend hours researching how to fix this, post here as a last resort, then I figure out what the problem is 30 minutes later.

For the record, the problem was in the php functions being called. They included sections where the closing div tag was enclosed in an if statement.

The if statement simply checked to see if the user was logged in, and even though this was true apparently making an ajax call in this way fails such an if statement, hence the closing div tag was never added.

I'd like to thank Nick for responding, as that helped trigger an idea about where the problem might be.


Need Your Help

High Quality Scaling of UIImage

ios image uikit uiimage

I need to scale the resolution of an image coming from a view layer in an iPhone application. The obvious way is to specify a scale factor in UIGraphicsBeginImageContextWithOptions, but any time the

Canvas Complete Drawing

javascript html5 canvas

i'm developt a new proyect=, it is in html5 using canvas for draw elements.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.