SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow get html - JQuery ?

    Hi guys

    This is my first time learning ajax using jquery.

    My get-html.htm:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
      <style>
      div { font-size:14px; }
      </style>
      <script src="http://code.jquery.com/jquery-1.5.js"></script>
    </head>
    
    
    <body>
    <div id="myDiv"></div>	
    	
    <script>
    	$.ajax({
        url: "test.html",
        type: "GET",
        dataType: "html",
        success: function(html)
            {
    					$('#myDiv").html(html);
    				}
      });		
    </script>
    
    </body>
    </html>

    And my test.html;
    Code:
    <html>
    <head>
    </head>
    
    <body>
    <p>This is from external file, test.html</p>
    </body>
    </html>

    By the way I run this and it did not show anything.
    I know this is really very basic, What is the problem with this?
    But please consider because I'm really new to jquery/ajax

    Thanks in advanced.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Your problem lies with the following line

    Code JavaScript:
    $('#myDiv").html(html);

    You have a single and double quote when it should be 2 single quotes wrapping myDiv

    Code JavaScript:
    $('#myDiv').html(html);
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow

    Thanks guys

    By the way I already fixed the qoutes problem.
    But I still don't see anthing.

    why?

    thanks in advanced.

  5. #5
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work. I just tested on my localhost.

  6. #6
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    A better solution i would recommend is to use jQuery.load() which uses a silent request to grab the file.
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle


Bookmarks

Posting Permissions

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