/    Sign up×
Community /Pin to ProfileBookmark

POSTing data via XMLHTTP

Hi All,

I need to pass a whole lot of parameters to a web page via the XMLHTTP POST option, but the parameters arn’t being sent.

[CODE]
sUrl = ‘AddToSelection.aspx’;
sQueryString = ‘companyID=’ + CompanyID + ‘&documentTreeID=’ + documentTreeID;

try {
if (XMLReaderObj != null) {
if (XMLReaderObj.readyState != 0) { XMLReaderObj .abort(); } // Abort the previous attempt
XMLReaderObj = null; // remove the HTTP connection
}
XMLReaderObj = getXMLHTTP(); // Open a new HTTP connection

XMLReaderObj.open(‘POST’, sUrl, false);
XMLReaderObj .setRequestHeader(‘Content-Type’,’application/x-www-form-urlencoded’);
XMLReaderObj.send(sQueryString);

} catch(e) { alert(e) } // Catch any major errors
[/CODE]

[CODE]
// Get a new HTTP connection
function getXMLHTTP() {
var AX = null;
try {
AX = new ActiveXObject(‘Msxml2.XMLHTTP’);
} catch(e) {
try {
AX = new ActiveXObject(‘Microsoft.XMLHTTP’);
} catch(oc) {
AX = null;
}
}

if(!AX && typeof XMLHttpRequest != ‘undefined’) {
AX = new XMLHttpRequest();
}

return AX;
}
[/CODE]

Can anyone tell me what I’m doing wrong ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinMay 04.2007 — first of all your getXMLHTTP method would be better starting with AX = new XMLHttpRequest() inside a try block...if that fails, then go for the others.

the reason for this is that ie now also uses XMLHttpRequest().

next, create a string that is sUrl + "?" + sQueryString

and instead of your POST do a GET, drop the false: i.e.,
<i>
</i>XMLReaderObj.open('GET', sUrl + "?" + sQueryString);
XMLReaderObj.send(null);


you can set your content type in the server-side script

then in your server side script check for GET instead of POST

anyway, I know people will *****, but that is pretty much the way I do it and it works every time
Copy linkTweet thisAlerts:
@Fred_NerksauthorMay 04.2007 — Thanks for the reply CrazyMerlin, but the whole reason I need to use POST is that I have to pass so much data that a GET wont work.

Also, why should I start with AX = new XMLHttpRequest(), isn't the XMLHTTP ActiveXObject 'better' (i.e optimised) for IE?
Copy linkTweet thisAlerts:
@Fred_NerksauthorMay 04.2007 — I found out what the problem was (stupid really :o )

In the web page I was calling I was using Request.QueryString() instead of a Request.Form()

Oops!
×

Success!

Help @Fred_Nerks spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...