[Wylug-help] Javascript and anonymous functions

Gary Stainburn gary.stainburn at ringways.co.uk
Wed Jul 3 20:25:56 UTC 2013


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 



More information about the Wylug-help mailing list