[Wylug-help] Javascript and anonymous functions
James Holden
wylug at jamesholden.net
Thu Jul 4 08:35:25 UTC 2013
Hi Gary,
No idea, my JS is limited to a bit of jQuery. You might try asking in #leedsjs
on irc.freenode.net though.
This might help though:
http://stackoverflow.com/questions/2559318/how-to-check-for-undefined-or-null-variable-in-javascript
Regards,
James
On Wed, Jul 03, 2013 at 09:25:42PM +0100, Gary Stainburn wrote:
> I use AJAX on some of my web sites, and call it using the following code
>
> var form=document.getElementById('testForm');
> AjaxRequest("/test8.php?formSubmit",function(xmlHttp) {
> if(xmlHttp.readyState==4) {
> generic_response(xmlHttp);
> }
> },form);
>
> Which works fine. I have been trying to make the function argument accept
> undefined or null as an argument. However, when I try to define the function
> it is called immediately instead of the callback.
>
> The core I've tried is below. Can anyone see what's wrong with it?
>
> function AjaxRequest(Url,Fn,form,modal=false) {
> var xmlHttp;
> var requestComplete=0;
> var requestResponse='';
> var Func;
> if (typeof(Fn) === "undefined" || Fn === null) {
> Func=(function(xmlHttp) {
> if(xmlHttp.readyState==4)
> generic_response();
> });
> } else {
> Func=Fn;
> }// Fn undefined
>
>
>
>
>
>
> --
> Gary Stainburn
> Group I.T. Manager
> Ringways Garages
> http://www.ringways.co.uk
>
> _______________________________________________
> Wylug-help mailing list
> Wylug-help at wylug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/wylug-help
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://mailman.lug.org.uk/pipermail/wylug-help/attachments/20130704/964d6f89/attachment.pgp>
More information about the Wylug-help
mailing list