[Wylug-help] Javascript and anonymous functions

Gary Stainburn gary.stainburn at ringways.co.uk
Thu Jul 4 08:38:47 UTC 2013


Cheers James, I'll bob over there if I get the chance.

The checking for undefined / NULL but works fine. It's the definition of the 
callback function instead of running it that I'm struggling with

Gary

On Thursday 04 July 2013 09:35:17 James Holden wrote:
> 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-nu
>ll-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



-- 
Gary Stainburn
Group I.T. Manager
Ringways Garages
http://www.ringways.co.uk 



More information about the Wylug-help mailing list