Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remote call twice in one page

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
I'ma bit confused. I have this simple remote call script, but when i call it twice to load two different objects, It only seems to work for the last call. It seems like one is preempting the other. Make sense?

Code:
function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

var http = createRequestObject();

function sndReq(page,target) {
    http.open( 'get', page );
    http.onreadystatechange = function(){
		 if ( http.readyState == 4 ) {
        var response = http.responseText;
        document.getElementById(target).innerHTML = response;
		}	
	};
    http.send(null);
}

These are executed after both target ids are loaded.
Code:
<script type="text/javascript">
sndReq('pop_contact_timeoff.asp?contact_id=123&mode=display','contact_time_off');
sndReq('pop_contact_timeoff.asp?contact_id=123&mode=display','contact_notes');
</script>
 
[tt][red]//[/red]var http = createRequestObject();

function sndReq(page,target) {
[blue]var http = createRequestObject();[/blue]
http.open( 'get', page [green], true[/green]);
http.onreadystatechange = function(){
if ( http.readyState == 4 ) {
var response = http.responseText;
document.getElementById(target).innerHTML = response;
[blue]http=null;[/blue]
}
};
http.send(null);
}
[/tt]
 
There are may ways around this issue... you could create 2 copies of the functions, or better still, create 2 instances of an object with those functions as method calls (don't forget to bind the callback to the instance in question).

You should ask for more help with any AJAXy stuff in this forum: forum1600.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top