473,608 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to implement an Ajax script?

7 New Member
This is a script that, when a link is clicked, will pull a page from somewhere and insert it in a div in the current page. Pretty simple, yes, but being the thick head I seem to be, I can't figure out how to implement it.

i.e. how to formulate the link so that it will point the script to the page we want to load in the div we want?

The script:
Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function() {  
  2.  
  3.     // Check for hash value in URL  
  4.     var hash = window.location.hash.substr(1);  
  5.     var href = $('#nav li a').each(function(){  
  6.         var href = $(this).attr('href');  
  7.         if(hash==href.substr(0,href.length-5)){  
  8.             var toLoad = hash+'.html #content';  
  9.             $('#content').load(toLoad)  
  10.         }   
  11.     });  
  12.  
  13.     $('#nav li a').click(function(){  
  14.  
  15.     var toLoad = $(this).attr('href')+' #content';  
  16.     $('#content').hide('fast',loadContent);  
  17.     $('#load').remove();  
  18.     $('#wrapper').append('<span id="load">LOADING...</span>');  
  19.     $('#load').fadeIn('normal');  
  20.     window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);  
  21.     function loadContent() {  
  22.         $('#content').load(toLoad,'',showNewContent())  
  23.     }  
  24.     function showNewContent() {  
  25.         $('#content').show('normal',hideLoader());  
  26.     }  
  27.     function hideLoader() {  
  28.         $('#load').fadeOut('normal');  
  29.     }  
  30.     return false;  
  31.  
  32.     });  
  33. });
  34.  

The instructions specify the following:

1. We want to target the links within the navigation menu and run a function when they are clicked:
Expand|Select|Wrap|Line Numbers
  1. $('#nav li a').click(function() {  
  2.     // function here  
  3. });
  4.  

2. We need to define what page to get the data from when a link is clicked on:

Expand|Select|Wrap|Line Numbers
  1. var toLoad = $(this).attr('href')+' #content';

3. The loadContent function calls the requested page:

Expand|Select|Wrap|Line Numbers
  1. function loadContent() {  
  2.     $('#content').load(toLoad,'',showNewContent)  
  3. }  

It's very likely that the above is all that's needed to run the script as intended but only if you know how to do it, which I don't.

I will be much obliged if the experts here care to give me a guiding hand.

PS: The tutorial all this comes from is here:
http://net.tutsplus.com/javascript-a...t-with-jquery/
Jul 3 '09 #1
3 1692
acoder
16,027 Recognized Expert Moderator MVP
That should be all that's required. Can you post the HTML code for the page?
Jul 4 '09 #2
BobBlock
7 New Member
acoder,
Thank you for responding.

The HTML code for the page would be meaningless because there is as yet no link associated with the script in it.

The reason being I haven't been able to figure out how to construct such a link; I don't know what to include, in what form and order, etc.

Can you give me a working link example that will point the script to the page we want to load, in the div we want? I suspect that will put me on the right track.

Cheers!
Jul 4 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
The script is unobtrusive, i.e. it provides the effect, but if someone doesn't have JavaScript enabled, it will still work. There's nothing special about the links. They're just normal links. See the demo - check the source code.
Jul 5 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1556
by: Gaffar | last post by:
Hello. My name is Gaffar. I am handling an module in a Project. This application interface is slow and inefficient. So Client told "implement an AJAX Solution which will increase speed and efficiency and user's experience". So, My problem is what is AJAX Solution. How to implement that. what are the feataures. Please give with a sample solution. Thanx in advance. Regards Gaffar.
21
6124
by: javainfo | last post by:
How can i refresh IFRAME and load data through AJAX?
1
16491
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX - microlink pattern tutorial : A microlink is a link that opens up
3
2973
by: noballack | last post by:
I've got a problem, I'm working with Ajax in a web with a form with a list of checkbox added to the form via an Ajax.Updater method. These added checkboxs are not been sended by the form if I use Firefox or Safari. My source code is something like that: <script type="text/javascript" src="http://www.my_web_page.com//js/prototype-1.4.0.js"></script> <script> function showMoreOptions( url, pars, div_id ){ if...
10
4849
by: trpost | last post by:
I am using ajax / php where I am looking up some info from the database and populating a select list dynamically, however I am running into some sort of size limitation with the ajax.response object. If the string I am passing to javascript from php is too large javascript does not get it all the data. The magic number appears to be 6123 characters, anything below that it works fine, anything above and if I alert the ajax.response, I see...
2
4254
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously functioning as desired when I test it on my machine using Visual Studio 2005. From what I have determined, the files I am forgetting are the JavaScript files from the Microsoft AJAX Library (See "To install Microsoft AJAX Library" at the bottom of...
10
3450
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario ------------- I have perl script which simply runs a ps on a Solaris server and generates a static html page with all of the code perfectly and this html page works fine when viewing it statically or with a META REFRESH header tag. The idea is to give the user...
7
4596
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
我们现在遇到一个问题,通过wcf创建的webservice,选择windows service作为宿主,采用java作为客户端调用成功,但是无法使用asp.net ajax调用。 我们参考了http://msdn.microsoft.com/zh-cn/library/bb410780.aspx的资料,并且下载了相应的sample code,但是发现这些sample基本上都需要在iis上部署一个svc文件,但是根据当前业务需求,我们无法部署iis服务器。...
1
3273
by: nehalsmistry | last post by:
Hello.. I am using visual studio 2005. So there is framework 2.0 Now I m using ajax toolkit for 2.0 and installed it. But there is no option like Asp.net ajax enable website. But there is 1 option like Ajax control toolkit website. When i select this website then in default.aspx page there is one control like script manager. but in that also there is error. Its display like this: Error Creating Control- ScriptManager1 Unkown server...
0
8063
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8496
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6816
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4024
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.