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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with XMLHttp objects 1

Status
Not open for further replies.
Jun 9, 2006
159
US
I'm trying to learn to code "AJAX" types of functionality through javascript and the Microsoft.XMLHTTP object. I'm finding it terribly difficult to debug. Please take a look at the below code; this code never seems to get called:

http.onreadystatechange = handleCommentResponse;

When the sndComment() function is called it updates my div, but never seems to reach the handleCommentResponse() function, even though it is very straight forward (for testing purposes). Can someone take a look and help me figure out what I'm missing:

Code:
 var http = createRequestObject();
 function createRequestObject() 
     {
           var xmlhttp;
	 try 
                 { 
                    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
                 }
	  catch(e) 
                 {
	    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	    catch(f) { xmlhttp=null; }
	    }
	        if(!xmlhttp&&typeof XMLHttpRequest!="undefined") 
                        {
	  	   xmlhttp=new XMLHttpRequest();
	           }
		   return  xmlhttp;
 }

// SEND THE COMMENT

function sndComment(idnum,comment) 
  {
	var dvelement = document.getElementById('dv_Comment');
             dvelement.innerHTML = "<br><div style='color: black; padding: 10px; margin: 10px; font-color: black;'><br>Adding Comment<br><img src='img/progressimgred.gif'></div>";
            try
              {
                 http.open('GET', 'video/addComment.aspx?id='+idnum+'&rateval='+rateval);
                 http.onreadystatechange = handleCommentResponse;
	    http.send(null);
	 }
	    catch(e){}
	    finally{}
 } 

// Handle the http response
function handleCommentResponse()
{
    var dvelement = document.getElementById('dv_Comment'); 
    dvelement.innerHTML = "SomeText!";     
    alert('asdf'); 
}

Thank you very much!



Shawn Molloy
Seattle, WA
 
My advice - download and install Firefox, and then install the "Firebug" extension. It lets you inspect all outgoing and incoming XMLHTTP requests - so you can see if it is even being sent (and if your server is sending anything back).

Presumably you also want to take parameters in your "handleCommentResponse" function (i.e. your response data)?

BTW - There is now a dedicated AJAX forum (forum1600) which may be able to offer more help if you don't get any luck here.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
[1] Your comment variable passed is never used and your rateval is never defined; maybe you mean for comment or maybe not.
[2] You need one more variable to set the async to true.

This is the minimum you need to change to make it operational.

>http.open('GET', 'video/addComment.aspx?id='+idnum+'&rateval='+rateval);
[tt]http.open('GET', 'video/addComment.aspx?id='+idnum+'&rateval='+[red]comment[/red][red],true[/red]);[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top