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.

[/problem]

[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.

[/solution]

[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 ...

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

[/example]

[reference]

[tags][/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

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