Dear group,
i have some experience with javascript, but now i am trying to do object
oriented programming with it and i am somehow stuck.
I have tried the code so far only in Mozilla 1.7.3
I am trying to make an object which offers the functionaltity of the
xmlhttpRequest object ( my object is something like a wrapper ). the
constructor makes an new XMHttpequest object, and then there are methods
to POST or GET data.
The problem: I assigned a function to xmlhttp.onready statechange, which
(for now) only alerts the response from an php script. BUT in the
function i always get an error saying xmlhttp has no properties?!
thanks in advance (sorry for the bad english)
Bernhard
-
function xmlRequest() {
// check if request is already open
this.xmlhttp=fa lse;
if (!this.xmlhttp && typeof XMLHttpRequest! ='undefined') {
this.xmlhttp = new XMLHttpRequest( );
}
}
xmlRequest.meth od('postVal', function (url, content) {
// variables needed to post
this.url = url;
this.content = content;
// alert(this.xmlh ttp);
// very, very important to set sync to true and to set the request
header!!!
this.xmlhttp.op en("POST", this.url, true);
this.xmlhttp.se tRequestHeader( "Content-Type","applicat ion/x-www-form-urlencoded;
charset=ISO-8859-1");
this.xmlhttp.on readystatechang e = this.getRespons e;
this.content = "content=" + this.content;
this.xmlhttp.se nd(this.content );
});
xmlRequest.meth od('getResponse ', function () {
if (this.xmlhttp.r eadyState==4) {
alert(this.xmlh ttp.readyState)
}
});
if you wonder about the syntax xmlRequest.meth od, its just some sugar
Function.protot ype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
i have some experience with javascript, but now i am trying to do object
oriented programming with it and i am somehow stuck.
I have tried the code so far only in Mozilla 1.7.3
I am trying to make an object which offers the functionaltity of the
xmlhttpRequest object ( my object is something like a wrapper ). the
constructor makes an new XMHttpequest object, and then there are methods
to POST or GET data.
The problem: I assigned a function to xmlhttp.onready statechange, which
(for now) only alerts the response from an php script. BUT in the
function i always get an error saying xmlhttp has no properties?!
thanks in advance (sorry for the bad english)
Bernhard
-
function xmlRequest() {
// check if request is already open
this.xmlhttp=fa lse;
if (!this.xmlhttp && typeof XMLHttpRequest! ='undefined') {
this.xmlhttp = new XMLHttpRequest( );
}
}
xmlRequest.meth od('postVal', function (url, content) {
// variables needed to post
this.url = url;
this.content = content;
// alert(this.xmlh ttp);
// very, very important to set sync to true and to set the request
header!!!
this.xmlhttp.op en("POST", this.url, true);
this.xmlhttp.se tRequestHeader( "Content-Type","applicat ion/x-www-form-urlencoded;
charset=ISO-8859-1");
this.xmlhttp.on readystatechang e = this.getRespons e;
this.content = "content=" + this.content;
this.xmlhttp.se nd(this.content );
});
xmlRequest.meth od('getResponse ', function () {
if (this.xmlhttp.r eadyState==4) {
alert(this.xmlh ttp.readyState)
}
});
if you wonder about the syntax xmlRequest.meth od, its just some sugar
Function.protot ype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Comment