Jump to content

jQuery:how to build url ?


anatak
Go to solution Solved by anatak,

Recommended Posts

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
Share on other sites

  • Solution

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.