Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2011
    Location
    Romania
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Weird jQuery problem

    I have a basic page, called 'index.php' that has some content on it. When I click on a certain link, it reloads the content of a certain div with the contents of the file called 'blog.php'.

    'blog.php' contains a link that has a class attribute = 'more':
    Code:
    <a href="#" class="more" id="<?php echo $id; ?>">load more</a>
    And I have the following javascript code, in a separate file called 'loadmore.js'(the connection to this file is made in index.php)
    Code:
    $(function() {
    	$('.more').on("click",function() {
    	        var ID = $(this).attr("id");
    		if(ID) {
    			$("#more"+ID).html('<img src="/./images/loading.gif"/>');
    			$.ajax({
    				type: "POST",
    				url: "/./server_scripts/ajax_more.php",
    				data: "lastmsg="+ ID, 
    				cache: false,
    				success: function(html){
    					$("#main_body").append(html);
    					$("#more"+ID).remove(); // removing old more button
    				}
    			});
    		}
    		else {
    			$(".morebox").html('The End');// no results
    		}
    	return false;
    	})
    });
    However, when I click on my link and I have breakpoints in my .js file, nothing happens, it just redirects me to the top of the page.
    Do you have any idea what might be wrong?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,212
    Thanks
    23
    Thanked 605 Times in 604 Posts
    Your jquery code is good. But we don't see all your html or the url: "/./server_scripts/ajax_more.php", file and if your published code is good then one of those is bad.

    Where does this
    PHP Code:
    <?php
    $id 
    2;
    ?>
    Occur?
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •