Solved

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

Posted on 2010-09-13
7
428 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

786 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