Link to home
Start Free TrialLog in
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/#)
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Phazz
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?
both should works on all browsers.
Avatar of Phazz

ASKER

Thanks for your help.
thanks for the points