/    Sign up×
Community /Pin to ProfileBookmark

Problems with: Microsoft.XMLHttp

Hi guys,

I’m trying to write a script to dynamically grab data from a data base. When the page is rendered, php and mysql do their thing and create a table of all the information. When I click on one of the names of each item, the text box beside it will grab data from the database and stick it in the textarea.

My problem is that when I call the getHistory() function, I want to pass two parameters to it: the ID (input) of the title being clicked and then the Output ID of the textarea for that individual “row” of data.

But my problem becomes that I can only pass the input parameters…but can’t actually put the output where I want them to go because the onreadystatechange handler is OUTSIDE of the getHistory function…

So basically, how can I add the handleHttpResponse function to be included in the getHistory function so that I can easily pass multiple parameters into it. Thanks! Here’s the code:

PS – Once again sadly only testable in IE.

[CODE]var url = “phpfile.php?getHist=”;
var http = new ActiveXObject(“Microsoft.XMLHTTP”);
function getHistory(input) {
http.open(“GET”, url+input, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function handleHttpResponse() {
if (http.readyState == 4) {
results = http.responseText;
document.getElementById(‘OUTPUT-ID-HERE’).value = results;
}
}[/CODE]

Want it to “look” like this:

[CODE]var url = “phpfile.php?getHist=”;
var http = new ActiveXObject(“Microsoft.XMLHTTP”);
function getHistory(INPUT,OUTPUT) {
http.open(“GET”, url+INPUT, true);
http.onreadystatechange do this:
if (http.readyState == 4) {
results = http.responseText;
document.getElementById(‘OUTPUT’).value = results;
}
http.send(null);
}
}[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@paradoxperfectauthorJan 25.2007 — *bumpity..*
Copy linkTweet thisAlerts:
@pcx99Jan 25.2007 — Create a global variable (IE a variable that is not inside either one of your functions).

var _dropDiv=null

In getHistory assign the division to the global variable...

<i>
</i>function getHistory() {
_dropDiv = document.getElementById("currentDiv");
blah
blah
blah
}


Now your handle function..

<i>
</i>function handleHttpResponse() {
if (http.readyState == 4) {
results = http.responseText;
_dropDiv.value = results;
}
}


This will be ok unless you're making concurrent calls in which case you will need another solution.
Copy linkTweet thisAlerts:
@paradoxperfectauthorJan 25.2007 — Actually yest I am making concurrent calls... I already tried using a global variable...but with no luck doing the simultaneous calls. Have any other solutions? Thanks!
Copy linkTweet thisAlerts:
@paradoxperfectauthorJan 25.2007 — Woot, I got it working... just put a second parameter for the first function. Should this be OK to use? Thanks! ?

var url = "phpfile.php?getHist=";
var http = new ActiveXObject("Microsoft.XMLHTTP");
var output
function getHistory(add,history) {
http.open("GET", url+add, true);
http.onreadystatechange = handleHttpResponse;
output = document.getElementById("output"+history);
http.send(null);
}
function handleHttpResponse() {
if (http.readyState == 4) {
results = http.responseText;
output.value = results; //Replaced from {$myrow['pc_history']}
}
}
×

Success!

Help @paradoxperfect 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.20,
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,
)...