• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

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/#)
0
Phazz
Asked:
Phazz
  • 4
  • 2
2 Solutions
 
Gurvinder Pal SinghCommented:
<<The browser looks for litterally "#" at the root of my website>>
Does the AjaxFunction() method gets called?
0
 
Gurvinder Pal SinghCommented:
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
 
djuzoranCommented:
try:
<a href="" onclick="AjaxFunction();return false;">link</a>
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
PhazzAuthor Commented:
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
 
Gurvinder Pal SinghCommented:
both should works on all browsers.
0
 
PhazzAuthor Commented:
Thanks for your help.
0
 
Gurvinder Pal SinghCommented:
thanks for the points
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now