So this is a part of a simple JavaScript code to handle xmlhttprequest. The part that is generating the error is at the bottom (else if):
httpReq.onreadystatechange = function(){
if (httpReq.readyState == 4) {
if (httpReq.status == 200) {
var strRes = httpReq.responseText;
if(xmlOrig) strRes = (new $Xml(strRes, true)).conteudo(xmlOrig);
if(elemDest) $id(elemDest).innerHTML = strRes;
if(func) {
var dadosArray = new Array(4, strRes, httpReq, 'OK', 'Concluído com sucesso.');
window[func](dadosArray);
}
} else {
if(elemDest) elemDest.innerHTML = 'Erro: '+httpReq.status+' | '+httpReq.statusText;
if(func) {
var dadosArray = new Array(4, false, httpReq, 'erro', 'Erro, conteúdo não carregado!');
window[func](dadosArray);
}
}
} else if(func){
console.log("func? "+typeof(func));
var dadosArray = new Array(httpReq.readyState);
window[func](dadosArray); // <-- HERE IS THE ERROR!
}
}
However, the console.log return the "func" argument as a function, so where is the error?
The Safari console:
func? function TypeError: 'undefined' is not a function (evaluating 'windowfunc')
funcis? You're not passing it in or defining it anywhere?