DCIntheMAstateofmind
New Member
I'm currently learning PHP through a real website project and want to use Ajax calls to change sections of the website. CODE SAMPLEmyproject.js$(document).ready(function() { $("#inventory").click(function() { $.ajaxSetup({ url: "sectionhandler.php?section='inventory'", type: "get", dataType: "html" }); $.ajax().done(function(html) { alert(html); // This works! $("#section").html(html); // This doesn't work. $("#section").append(html); // This neither. }); });});inventory.html<table><tr><td>Hello world with AJAX!</td></tr></table>sectionhandler.php<?php echo file_get_contents( 'inventory.html' ); ?>menu.html<a id="inventory" href="">Inventory</a>index.php<div id="menu" class="content"><?php echo file_get_contents( 'menu.html' ); ?></div><div id="section" class="content"></div> RELATED ARTICLES FOUND AND READ AND TRIEDXMLHttpRequest won't work in IE 7/8 but works in other browsersjQuery.ajax()jQuery.ajaxSetup().append()jquery .html() vs .append()Can't append HTML code into one div by using jQueryAdd Html to Div with effect jQueryUse append() to add text/html to an element with jQueryAnd there are many many more... RESULTWhen I click on the Inventory link contained within menu.html and displayed through index.php, the jQuery code executes just fine. I get the result from the server while displaying the right content from inventory.html in the alert().However, when I come to either set the innerHTML to the <div id="section" class="content"></div>, I can't seem to be able to get the expected result. The background of the page seems to flash, though not supposed to as per Ajax definition, and the content of my XMLHttpRequest.responseText never get displayed.The closer I got to make it work was when I was double-clicking on the Inventory link, so that after the first "flash" from the page background, it showed the content of my section.I have tried multiple ways using classic Javascript with an onclick element on my <a> tag, I have tried with document.getElementById("section"), though getting the right element, I was not able to show my content on the page.Any thoughts are welcome!Thanks in advance ! =)