Your code seems ok to me except that it doesn't allow you to send HTTP POSTs the right way.
In a HTTP POST, parameters should be in the HTTP Body, not in the URI. The error message shows parameters are being appended to the URI.
[HTML]
POST /OmniPreferedRoaming/Omni%20Preferred%20Roamer/Action/add-operator-action.jsp?action=add&opCountry=CAN&opName=can2&opCC=456&opNDC=6325&opMCC=156&opMNC=0036&sid=0.6507964352578459 HTTP/1.1
[/HTML]
I don't think it really matters if its in the URI though. You just have to make sure each parameter is urlencoded if you place it in the URI.
Heres an example taken from a larger class/object:
[HTML]/**
* encode passed http vars
*/
fwd_XHR.prototype.encode = function(uri) {
if (encodeURIComponent) {
return encodeURIComponent(uri);
}
if (escape) {
return escape(uri);
}
return uri;
};
/**
* dencode passed http vars
*/
fwd_XHR.prototype.decode = function(uri) {
uri = uri.replace(/\+/g, ' ');
if (decodeURIComponent) {
return decodeURIComponent(uri);
}
if (unescape) {
return unescape(uri);
}
return uri;
};[/HTML]
If you append parameters to the HTTP body in a HTTP POST, you should also specify the Content-Type header as "application/x-www-form-urlencoded". Assuming you want it to be parsed by the server into HTTP POST parameters.
Try something like:
[HTML]function sendPOST(url, data){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
data += "&sid="+encodeURIComponent(Math.random());
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.setRequestHeader("Method", "POST "+url+" HTTP/1.1");
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// one of the error message suggestions is to include content-length header. so try that...
xmlHttp.setRequestHeader("Content-Length", encodeURIComponent(data.length));
xmlHttp.send(data);
}[/HTML]
Call it like:
[HTML]
// the uri has to be url encoded
url = '/OmniPreferedRoaming/Omni%20Preferred%20Roamer/Action/add-operator-action.jsp';
// so does each param value
data = 'action='+encodeURIComponent('add');
data += '&opCountry='+encodeURIComponent('CAN'); // etc.[/HTML]
Also note I included the content-length header which is suggested in teh error message.
Don't think this is related but in the code:
[HTML]xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.send(null);[/HTML]
you might want to change to:
[HTML]
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.send(null);[/HTML]
(I think there is a problem that arises in one of the browsers where the xmlhttprequest resets the object when you call the "open" method - but that might be in IE)
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!