Solved

How to call a AJAX javascript funtion when clicking a link on a CGI generated HTML page?

Posted on 2010-09-13
7
415 Views
Last Modified: 2013-12-25
My CGI application generates HTML code with links to some (precomputed) data on the server. The data is not used for anything unless the user clicks the link. Now I want to optimize the application using AJAX to generate the data on the fly only when the user clicks the link.

The following code would work in a normal HTML page:
<a href="#" onclick="AjaxFunction();return false;">link</a>

But it doesn't work in my case, I guess because the HTML page with the links was generated by the CGI. The browser looks for litterally "#" at the root of my website (www.example.com/#)
0
Comment
Question by:Phazz
  • 4
  • 2
7 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33660599
<<The browser looks for litterally "#" at the root of my website>>
Does the AjaxFunction() method gets called?
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 33660605
when you have given onclick, href is not required, so either you can
1) remove href="#".
2) give href= "javascript:AjaxFunction()"; and remove onclick
0
 

Assisted Solution

by:djuzoran
djuzoran earned 250 total points
ID: 33660768
try:
<a href="" onclick="AjaxFunction();return false;">link</a>
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Phazz
ID: 33660936
Thanks to both of you!

Guruvinder372's first suggestion doesn't work, but the second one works perfectly. Djuzoran's suggestion works too.

Actually I found out that my original code in the question also works! - but my AjaxFunction wasn't executed (misspelled function name, embarrassing, huh?)

Is any of the suggestions best in terms of cross-browser support?
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33660959
both should works on all browsers.
0
 

Author Closing Comment

by:Phazz
ID: 33661616
Thanks for your help.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33661633
thanks for the points
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now