PHP - Moved: Why My Div Content Is Not Refreshing By Ajax In Ie
Stop posting non-PHP questions in the PHP Coding Help section. We have many sub-forums, including both a JavaScript forum and one dedicated entirely to Ajax.
This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=327454.0 Similar TutorialsThis topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330523.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=347117.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=349726.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=323252.0 Hello all,
I feel pretty good that I got my AJAX filter working properly. But it still needs some help. Now I am returning the content with Ajax that I want from the search filter of dropdown option (keep in mind there are several options to filter by). But the content returned is often to much to fit on one page - so I need to paginate the successfully returned html from my AJAX call.
Here is where I get stumped. Do I setup a normal page nav outside the AJAX area?
</div><!-- AJAX return container--> <nav class="pagenav"> <ul id="pag-link"> <li class="old"><?php next_posts_link('« Older Sermons', $sermons_query->max_num_pages) ?></li> <li class="new"><?php previous_posts_link('Newer Sermons »', $sermons_query->max_num_pages) ?></li> </ul> </nav>IF so, how do I update the links info? or do I keep the page nav inside the AJAX area but use some custom code to retrieve the proper link? (I tried using the normal wordpress page nav functions in my php function but they provide the url of the page that the php function is on, not the actual page being viewed). Do I need to make a separate AJAX call to a function that just builds my links? or is there a way to do it with my main call? Here is my AJAX call: //Listen for the menu's to change except the main filter_by dropdown var ids = ['filter_preacher_dropdown', 'filter_sort_by_dropdown', 'filter_per_page_dropdown', 'filter_series_dropdown', 'filter_service_dropdown', 'filter_tag_dropdown', 'filter_book_dropdown', 'filter_year_dropdown']; $('#' + ids.join(',#')).change(function(e) { var pt = [ "preacher","series","service" ]; if($.inArray(this.name, pt)!==-1){ var mk = this.name; var mv = $(this).val(); var ppp = $("#filter_per_page_dropdown").val(); var ob = $("#filter_sort_by_dropdown").val(); var data = { action: 'filter_sermons', meta_key: mk, meta_value: mv, posts_per_page: ppp }; $.post(mbsb_ajaxurl, data, function(response) { $('#sermonlists').fadeOut('slow', function() { $(this).html(response) }).fadeIn('slow'); }); }and here is my php function (slightly paired down for viewing ease): //ajax for sermons filter add_action('wp_ajax_filter_sermons', 'check_ajax'); add_action('wp_ajax_nopriv_filter_sermons', 'check_ajax'); function check_ajax() { global $wpdb, $paged, $max_num_pages; //check if filter is on post_type if($_POST['meta_key']){ $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $mk = '"'.$_POST['meta_key'].'"'; $mv = intval($_POST['meta_value']); $ppp = intval($_POST['posts_per_page']); $offset = ($paged - 1) * $ppp; $sermons = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS sermons.* FROM {$wpdb->prefix}posts AS sermons, {$wpdb->prefix}postmeta WHERE meta_key = {$mk} AND meta_value = {$mv} AND sermons.ID = {$wpdb->prefix}postmeta.post_id LIMIT {$offset}, {$ppp}", OBJECT); $sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" ); $max_num_pages = ceil($sql_posts_total / $ppp); }elseif($_POST['name']){ //another custom query }elseif ($_POST['book_number']){ //another custom query } $posts = get_posts(); // returns posts in an array if($sermons) { global $post; foreach ($sermons as $post){ setup_postdata($post); //custom query info returned here } //Would the Pagination for the AJAXED content go here? }else{ ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php } die(); } Hi All,
Am hoping someone can point out my perhaps obvious issue here.
I've a series of links that are dynamically created:
<a class="team-link" rel="<?php the_ID(); ?>" href="#">When a link is clicked, I'm trying to get content to load into this DIV: <div id="single-post-container"></div>I have the following jquery: <script> $(document).ready(function(){ $.ajaxSetup({cache:false}); $(".team-link").click(function(){ var post_id = $(this).attr("rel"); $.ajax({ url : "http://www.domain.co.uk/wp-content/themes/name/loop.php", data : {"the_team": post_id }, type : "POST", dataType : "html", success: function(response) { $("#single-post-container").html(response); } return false; }); }); </script>This is my loop.php file: require_once('../../../wp-load.php'); // Our variables $the_team = (isset($_GET['post_id'])) ? $_GET['post_id'] : 0; echo $the_team; query_posts(array( 'post_type' => 'work', 'meta_key' => 'author_name', 'meta_value' => $the_team )); // our loop if (have_posts()) { while (have_posts()){ the_post(); ?> <h1><?php the_title(); ?></h1> <?php the_content(); ?> <hr /> <?php } } wp_reset_query();However, when you click the link, nothing happens. I know loop.php works as I can specify a value and manually browse to it to see the content. I feel I'm missing something obvious as I'm new to AJAX. Your help/patience is very much appreciated This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=312841.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=333348.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=351379.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=325858.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=309753.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=308756.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=319274.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=347835.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=320161.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=350592.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=323434.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=348693.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=314220.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=314117.0 |