More information on this topic is available in the documentation section: /active.http.request/.
obj.setParameter = function(name, value){
this["_" + name + "Parameter"] = value;
if (!this._parameters.match(name)) {this._parameters += " " + name}
};
I set some parameter 'oldId' followed by another parameter 'Id'. The second parameter is ignored :-( Call to String.match is the culprit. Better regex pattern can fix this.obj.setParameter = function(name, value)
{
if (!this["_" + name + "Parameter"])
this["_" + name + "Parameter"] = new Array(value);
else
{
var a = this["_" + name + "Parameter"];
a[a.length] = value;
}
if (!this._parameters.match(name))
{
this._parameters += " " + name
}
};
And then the first part of the request function as:obj.request = function(){
var self = this;
this._ready = false;
var i, name, value, data = "", params = this._parameters.split(" ");
for (i=1; i<params.length; i++)
{
name = params[i];
value = this["_" + name + "Parameter"];
for (var z = 0; z < value.length; z++)
{
data += name + "=" +
((typeof value[z] == "function") ? encodeURIComponent(value[z]()) :
encodeURIComponent(value[z])) + "&";
}
}
An example of making the call:function fooValue()
{
return "Scott Brand";
}
r.setURL("http://someurl");
r.setParameter("command","TYPELIST");
r.setParameter("key","idvalue");
r.setParameter("foo","1");
r.setParameter("foo","2");
r.setParameter("foo","3");
r.setParameter("foo",fooValue);
r.setRequestMethod("POST");
r.request();
When you post this to the server, you will see that the parameter "foo" has 4 values.if (!this._parameters.match(name))
{
this._parameters += " " + name
}
This will still ignore "value" parameter if you have set "old_value" parameter before. You should split the this._parameters string and then match name. This bug was also reported in past but.....function loadDoc(url) {
req = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
}
catch(e) {
req = false;
}
// branch for IE/Windows ActiveX version
}
else
if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
req = false;
}
}
}
if(req)
{
req.open("GET", url, false);
req.send("");
return req.responseText;
}
}
If I am returning JavaScript I just need to eval(loadDoc("URL")) and it executes the code immediately. Otherwise I can stuff the results into an array or do just about anything with the result. Works like a champ.AW.HTTP.Request.prototype.setParameter = function(name, value){
this["_" + name + "Parameter"] = value;
if (!this._parameters.match(new RegExp(" " + name + "( |$)"))) {
this._parameters += " " + name;
}
};
Active.HTTP.Request.prototype.setParameter = function(name, value){
this["_" + name + "Parameter"] = value;
if (!this._parameters.match(new RegExp(" " + name + "( |$)"))) {
this._parameters += " " + name;
}
};
obj.setRequestHeader = function(name, value){
this["_" + name + "Header"] = value;
if (!this._headers.match(new RegExp(" " + name + "( |$)"))) {this._headers += " " + name}
};
For multi value parameter someone has already suggested change.obj.request = function(){
var self = this;
this._ready = false;
var i, j, name, value, data = "", params = this._parameters.split(" ");
for (i=1; i<params.length; i++){
name = params[i];
value = this["_" + name + "Parameter"];
if (typeof value == "function") { value = value(); }
if (typeof value == "object" && value.constructor == Array){
for (j=0; j<value.length; j++){
data += name + "=" + encodeURIComponent(value[j]) + "&";
}
}
else {
data += name + "=" + encodeURIComponent(value) + "&";
}
}
...
(!this._parameters.match(new RegExp(" " + name + "( |$)")))
So, I suggest using indexOf function with extra space. The code will be :obj.setParameter = function(name, value){
this["_" + name + "Parameter"] = value;
if ((this._parameters + " ").indexOf(" " + name + " ") < 0) {
this._parameters += " " + name;
}
};
