anatak Posted September 8, 2013 Share Posted September 8, 2013 I have a navigation script and I want to load the contents using ajax. the navigation script calls the ajax function but I don't know how to pass the ajax function the a href="data to be loaded" part. to test the script I have 2.php in the ajax function so how can I make '2.php' a variable that will change with the click of the link ?thank you <ul id="navigation"> <li class="one"><a href="index.html">home</a></li> <li class="two"><a href="2.php">page 2</a></li> <li class="three"><a href="3.php">page 3</a></li> <li class="four"><a href="4.php">page 4</a></li> <li class="five"><a href="5.php">page 5</a></li> <li class="shadow"></li> </ul> <div id="content"> <h2>here comes the content from the requested page</h2> </div> </div> <script type="text/javascript"> $(document).ready(function(){ $("ul#navigation li a").click(function() { $("ul#navigation li").removeClass("selected"); $(this).parents().addClass("selected"); return false; }); }); $("ul#navigation li a").click(function(){ $("#content").load("2.php",function(responseTxt,statusTxt,xhr){ if(statusTxt=="success") alert("External content loaded successfully!"); if(statusTxt=="error") alert("Error: "+xhr.status+": "+xhr.statusText); }); }); </script> Link to comment https://forums.phpfreaks.com/topic/281971-jqueryhow-to-build-url/ Share on other sites More sharing options...
kicken Posted September 8, 2013 Share Posted September 8, 2013 use this.href to get the value of the href attribute. Link to comment https://forums.phpfreaks.com/topic/281971-jqueryhow-to-build-url/#findComment-1448690 Share on other sites More sharing options...
anatak Posted September 9, 2013 Author Share Posted September 9, 2013 kicken thank you for the suggestion. I could not get it to work but I found another script that I am using now. for everyone reading this thread who is, like me, a complete beginner with AJAX I recommend the following tutorial. http://tutorialzine.com/2009/09/simple-ajax-website-jquery/ the problem I have now is that the javascript that keeps the selected tab in the navigation menu breaks the ajax script. I will post about that in the Javascript forum as I think it is not appropriate here.thank you everyone for reading / helping. anatak Link to comment https://forums.phpfreaks.com/topic/281971-jqueryhow-to-build-url/#findComment-1448827 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.