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
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts

    $.ajax not working

    I have a script that was working with a jquery-1.4.2.min.js

    now i got rid of that and i have jquery.js on the page

    $.ajax({
    url: urltoajax,
    cache: false,
    success: function (html) {
    $("#mydiv").html(html);
    }
    });

    what is missing? my problem is the jquery-1.4.2.min.js conflicted with something else on the page that needed the jquery.js

    plese advise

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,095
    Thanks
    23
    Thanked 594 Times in 593 Posts
    my problem is the jquery-1.4.2.min.js conflicted with something else on the page that needed the jquery.js
    I really doubt this. The newest jq is ver 1.7.2.

    My thoughts on the code is, don't use html to mean the results that the called file sends back. It does work, but html has another meaning so why confuse things. Use
    Code:
    success: function (result) {
    Your file name needs to be in quotes. Is this the real file name
    Code:
    urltoajax
    ? Or a representation of it?

    Code that works:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <script src="./lib/jquery-1.7.2.min.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    $(document).ready(function() {
    	$("button").click(function(){
    
    		$.ajax({
    			url: "ajax.php",
    			cache: false,
    			success: function (result) {
    				$("#mydiv").html(result);
    			}
    		});
    
    	});
    });
    </script>
    
    </head>
    <body>
    <div id="mydiv">Ajax will write here</div>
    <button>Do AjAx Stuff</button>
    </body>
    </html>
    My ajax.php file is this:
    PHP Code:
    <?php
    echo 'made it';
    ?>


  •  

    Posting Permissions

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