M
Mariano
I have this function (ajaxRequest), inside this function there is an
anonymous function that call a new function (alteraDomanda).
alteraDomanda is a simple function that return a string value when
executed. I woould that this string could be readed out of the
anonymous function, exactly here:
alert("2: "+post_param);
XMLHttpRequestObject.send(post_param);
But, although i have defined post_param out of all functions, previous
code return me 2: undefined.
Another strang thing is that is alway executed alert("2:
"+post_param); for first, and after alert("1: "+post_param). The first
alert return me "2: undefined", the second alert "1: IN FUNCTION".
I would that all alert will read and print "IN FUNCTION", and... why
alert("2: "+post_param); is executed first of alert("1:
"+post_param);???
var post_param;
function ajaxRequest(func, src, type, p1, p2, p3, p4, p5, p6, p7) {
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
if(XMLHttpRequestObject) {
XMLHttpRequestObject.open(type, src, true);
if (type=='POST')
XMLHttpRequestObject.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
XMLHttpRequestObject.onreadystatechange = function(){
if (XMLHttpRequestObject.readyState == 1) {
// PRELOADER
} else if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
var xmlDocument = XMLHttpRequestObject.responseXML;
post_param = alteraDomanda();
alert("1: "+post_param);
}
}
if (type=='GET')
XMLHttpRequestObject.send(null);
else if (type=='POST'){
alert("2: "+post_param);
XMLHttpRequestObject.send(post_param);
}
}
}
function alteraDomanda() {
return "IN FUNCTION";
}
anonymous function that call a new function (alteraDomanda).
alteraDomanda is a simple function that return a string value when
executed. I woould that this string could be readed out of the
anonymous function, exactly here:
alert("2: "+post_param);
XMLHttpRequestObject.send(post_param);
But, although i have defined post_param out of all functions, previous
code return me 2: undefined.
Another strang thing is that is alway executed alert("2:
"+post_param); for first, and after alert("1: "+post_param). The first
alert return me "2: undefined", the second alert "1: IN FUNCTION".
I would that all alert will read and print "IN FUNCTION", and... why
alert("2: "+post_param); is executed first of alert("1:
"+post_param);???
var post_param;
function ajaxRequest(func, src, type, p1, p2, p3, p4, p5, p6, p7) {
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
if(XMLHttpRequestObject) {
XMLHttpRequestObject.open(type, src, true);
if (type=='POST')
XMLHttpRequestObject.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
XMLHttpRequestObject.onreadystatechange = function(){
if (XMLHttpRequestObject.readyState == 1) {
// PRELOADER
} else if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
var xmlDocument = XMLHttpRequestObject.responseXML;
post_param = alteraDomanda();
alert("1: "+post_param);
}
}
if (type=='GET')
XMLHttpRequestObject.send(null);
else if (type=='POST'){
alert("2: "+post_param);
XMLHttpRequestObject.send(post_param);
}
}
}
function alteraDomanda() {
return "IN FUNCTION";
}