Jump to content


Photo

jQuery:how to build url ?

ajax jquery

Best Answer anatak, 09 September 2013 - 05:45 AM

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....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

Go to the full post


  • Please log in to reply
2 replies to this topic

#1 anatak

anatak

    Advanced Member

  • Members
  • PipPipPip
  • 403 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 08 September 2013 - 06:32 AM

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>

takasi.8008@docomo.ne.jp
tourokum@0508.jp

#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,712 posts
  • LocationBonita, FL

Posted 08 September 2013 - 07:57 AM

use this.href to get the value of the href attribute.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 anatak

anatak

    Advanced Member

  • Members
  • PipPipPip
  • 403 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 09 September 2013 - 05:45 AM   Best Answer

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....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


takasi.8008@docomo.ne.jp
tourokum@0508.jp




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com