-1

i cant access to SayHello.ashx and i got this javascript error :

httpReq.open is not a function.

but the code work fine when i use an aspx page for answer xmlhttprequest :

httpReq.open("POST", "SayHello.aspx");  

where is the problem? can the problem be from my .ashx file ?

function callASHX() {
    var httpReq=XMLHttpRequest();        
    var x = document.getElementById('txtName').value; 
    var sendStr = "user_id=" + x;
    httpReq.open("POST", "SayHello.ashx");        
    httpReq.onreadystatechange = XMLHttpRequestCompleted;
    httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");      
    httpReq.send(sendStr);       
}

// initialize XMLHttpRequest object
function XMLHttpRequest() {
    var httpReq;
    try {
        // Opera 8.0+, Firefox, Safari
        httpReq = new XMLHttpRequest();
    }
    catch (e) {
        // IEBrowsers
        try {
            httpReq = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                httpReq = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                return false;
            }
        }
    }
    return httpReq;
}
biglibigli
  • 59
  • 3
  • 8

1 Answers1

0

You're not assigning the return object of XMLHttpRequest().

Try this:

function callASHX() 
{    
    var httpReq =  XMLHttpRequest();        
    ....
    if (httpReq)  //potentially this is 'false'!
    {
       httpReq.open("POST", "SayHello.ashx");  
       ....
    }
p.campbell
  • 98,673
  • 67
  • 256
  • 322
  • thanks for that, but again i got same error when compiler reach this line: httpReq.open("POST", "SayHello.ashx"); – biglibigli May 14 '11 at 15:43
  • noting,same error. the page goes for connecting to localhost and finish, noting show. i find error with developer toolbar in firefox 4 – biglibigli May 14 '11 at 15:54