<?

谢谢!

I have spent hours reading and trying tutorials. I cant seem to find a solution that works and I know it should be pretty easy but I struggle with AJAX. :(

I want to load Post content from a link in a div.Below is what I have. Can someone please help me with the JavaScript side? Thanks!

<ul>
    <?

I want to load this code in div #loadAjaxHere

<div class="myArtwork">
   <h2><?

Thank you for the help!!

Ok,I think I have solved this after a long process of trial and error.

This seems to work, but please let me know if it is not the correct way of doing this

Javascript:

jQuery.noConflict();
jQuery(document).ready(function($){
    $.ajaxSetup({cache:false});
    $("a.ajax").click(function(){
        var post_url = $(this).attr("href");
        var post_id = $(this).attr("rel");
        $("#tabs").html('<div class="loading">loading...</div>');
    $("#tabs").load(post_url);
    return false;
    });
});

The page where I want to display the post content (I am using custom post types called "artwork":

<ul class="container">
  <?

And the single post "single-artwork.

<?

Thanks!

这篇关于如何使用 Ajax onclick 加载 Wordpress Post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!