AJAX And Javascript Functions Gotcha

Problem

Spent many further hours debug my code on elizaclaire.darlingranges.com.

None of my javascript functions worked, in the resulting sub-request. Tried all sorts, even setting up an AJAX call, within the sub-request. Nothing worked.



Solution

Eventually through masses of trial and error, “discovered” I had to define the javascript function, with the main body of the code.

In other words, within the subrequest made through AJAX you can have javascript triggers (onclick, onsubmit, onchange …) – but have them call functions previous define in your original web page.



Example



------------------- demo.htm ------------------

....
function reset_cty() { .... }
...
var url="page_with_call_reset_cty.htm"
xmlhttp.open("GET",url, true)
-------------------------------------------------

----------- page_with_call_reset_cty.htm --------
...
... onclick = ... reset_cty ...

--------------------------------------------------



Reference

[tags][/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *