问题描述
我花了几个小时阅读和尝试教程.我似乎找不到有效的解决方案,我知道这应该很容易,但我在使用 AJAX 时遇到了困难.:(
我想从 div 中的链接加载 Post 内容.下面是我所拥有的.有人可以帮我处理 JavaScript 方面的问题吗?谢谢!
<?<?<li class="mytab"><跨度><h3><?<?
<div id="loadAjaxHere"></div>
我想在 div #loadAjaxHere 中加载这段代码
<h2><?谢谢你的帮助!!
解决方案 好的,经过长时间的反复试验,我想我已经解决了这个问题.
这似乎有效,但如果这不是正确的做法,请告诉我
Javascript:
jQuery.noConflict();jQuery(文档).ready(函数($){$.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);返回假;});});
我想在其中显示帖子内容的页面(我使用名为艺术品"的自定义帖子类型:
<?<?<li class="mytab"><h3><?"class="ajax"><?<?
<!-- 在#TABS 中加载单个帖子内容--><div id="tabs"></div>
还有一个帖子single-artwork.
<?<div class="tabcontent" id="tab-<?
<?
谢谢!
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!