3.2.0

Bug in 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.
Sudhaker Raj
August 26,
bump...
September 21,
Alex, Any update on this?

Also HTTP protocol also supports multiple values for single parameter name. Any plan of addressing this too.?
Sudhaker Raj
November 2,
I have just started to use AW, and ran across the same problem.
I have a lot of occasions to submit forms with multi-valued parameters.
I updated the http/request.js file by modifying the
obj.setParameter function as:

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.

Let's try and add these changes into the 2.0 release. Please.
Scott Brand
August 24,
Scott, thanks for the fix. I will try and bug Alex into including it in 2.0. I have not yet started using Active.HTTP.Request but I think I will need to soon. Does the response have to be formatted XML or can I just return JavaScript?
Jim Hunter
August 25,
I found out that you can return any type of data you want if you use
getResponseText(). BUT... the only browser that I found HTTP.Request works in is IE. The other browsers just don't do anything. This would make sense because the HTTP.Request is just a wrapper around the IE ActiveX XMLHttpRequest component. And this ActiveX is not found in the other browsers. Has anyone tried any of the third party JavaScript replacements for XMLHttpRequest? And have they worked in all browsers?
Jim Hunter
August 26,
Actually it works fine in Firefox as well. The HTTP.Request code will first try the ActiveX control if it is defined. Otherwise it will use the built in XMLHttpRequest object found in Firefox.

One limitation is however, if you want to use HTTPS only IE will support that right now.
Scott Brand
August 28,

Good job Scott, but I still see one problem.

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.....

@Jim, FYI the AJAX support is there in IE and Firefox both. But any browser other than IE does not accept non-XML response.

Cheers,
Sudhaker Raj
http://thej2ee.com
Sudhaker Raj
August 28,
I have a call back function for XML HTTP object
function ProcessResult(result)
{
var oDoc = result.documentElement.ownerDocument;
oDoc.setProperty("SelectionLanguage", "XPath");
oDoc.setProperty("SelectionNamespaces", ns);
...
}

It used to work well with Firefox, today I just downloaded new version of Netscape and got this error:

oDoc.setProperty is not a function
(included gecko.js but it won't work...)
Tuan
August 28,
Tuan, I think that might be related to the other threads about the new firefox version not working
AcidRaZor
August 29,
Thanks Sudhaker, but I did a bunch of testing and did not get the desired results across the various browsers. Since I want to send back a variety of info from pure data to JavaScript I ended up using a cross browser replacement for the MS Msxml2.XMLHTTP object (it uses it if IE only) and it's working great. I get the same functionality on all 4 major browsers which is all I need to support. Here is what I am using:

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.

Thanks everyone.
Jim Hunter
August 29,

Not fixed in activewidgets-2-0-b1 :-(

Sudhaker Raj
October 6,
Finally fixed this bug. :-( It will come in 2.0b2 and someday in 1.0.2.

Here is the patch:

AW.HTTP.Request.prototype.setParameter = function(name, value){
    this["_" + name + "Parameter"] = value;
    if (!this._parameters.match(new RegExp(" " + name + "( |$)"))) {
        this._parameters += " " + name;
    }
};
Alex (ActiveWidgets)
October 6,
Oops, for 1.0.1 it should be

Active.HTTP.Request.prototype.setParameter = function(name, value){
    this["_" + name + "Parameter"] = value;
    if (!this._parameters.match(new RegExp(" " + name + "( |$)"))) {
        this._parameters += " " + name;
    }
};
Alex (ActiveWidgets)
October 6,

In html we can have multiple values for some parameter (in case of checkbox or multi-select etc). What do you suggest for that?
Sudhaker Raj
October 6,

And similar change for headers

In request.js
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.

>> Scott Brand
>> Wednesday, August 24, 2005
Sudhaker Raj
October 6,
I would suggest that if typeof(value) is array then it is treated as multivalue parameter, so you can write:

r.setParameter("foo", [1,2,3]);

Then request method will look like this:

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) + "&";
            }
        }

...
Alex (ActiveWidgets)
October 6,

Even better ;-) You are genius Alex! Please have this merged in next release :-)
Sudhaker Raj
October 6,
There is always a error on SetParameter method.
matching is not correct.

If you set parameter named 'ID.[0]', request server (grid.refresh by example), change the value of this parameter and request server another time; your parameter is sent many time to server because your parameter is not recognize with :
(!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; 
    } 
};
Pascal
October 18,
yes, that's a very good point. Thank you, Pascal, I will change that part.
Alex (ActiveWidgets)
October 18,
Fixed in 1.0.2

http://www.activewidgets.com/javascript.forum.9654.0/maintenance-release-1-0-2.html
Alex (ActiveWidgets)
December 12,

This topic is archived.

See also:


Back to support forum