Avatar of Phazz
Phazz
 asked on

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

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/#)
Scripting LanguagesAJAXJavaScript

Avatar of undefined
Last Comment
Gurvinder Pal Singh

8/22/2022 - Mon
Gurvinder Pal Singh

<<The browser looks for litterally "#" at the root of my website>>
Does the AjaxFunction() method gets called?
ASKER CERTIFIED SOLUTION
Gurvinder Pal Singh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
djuzoran

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Phazz

ASKER
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?
Gurvinder Pal Singh

both should works on all browsers.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Phazz

ASKER
Thanks for your help.
Gurvinder Pal Singh

thanks for the points