locked
Problem creating XMLHttpRequest RRS feed

  • Question

  • User1358270947 posted

     Hi all

    I am trying to create an XMLHttpRequest object in javascript to call a ashx page. My code:

      

    function createXMLHttpRequest() {
            alert("Started createXMLHttpRequest");
            try return new XMLHttpRequest(); } catch(e) { alert (e)}
            try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { alert(e) }
            try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert(e) }
            alert("XMLHttpRequest not supported");
            return null;
        }
    
    
        function getImage(peopleID) {
            alert("Started getImage");
            var xmlHttpReq = createXMLHttpRequest();
            xmlHttpReq.open("GET", "PDetailHandler.ashx?id=10", false);
            xmlHttpReq.send(null);
            var picURL = xmlHttpReq.responseText;
            alert (picURL);
        }

     

    I am getting the following error when I call the createXMLHttpRequest method:

    "Could not complete the operation due to error c00ce514"

     Any ideas what I might be doing wrong here?

    Any help much appreciated

    Regards

    Thursday, April 16, 2009 8:48 AM

Answers

All replies

  • User1580727775 posted

    alert("Started createXMLHttpRequest"); try return new XMLHttpRequest(); } catch(e) { alert (e)} try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { alert(e) }

     

     

    You missed a "{" braces after the first try

    Thursday, April 16, 2009 9:17 AM
  • User1358270947 posted

     Thanks for the reply, I did notice that but still getting the error :[.

     

    Thursday, April 16, 2009 10:28 AM
  • User1677448765 posted

     <%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <script type="text/javascript" language="javascript">
    var xmlhttp = false;
    getHTTPRequestObject();
    if(xmlhttp)
    {
    xmlhttp.open("GET", "TextFile.txt", true);
    xmlhttp.onreadystatechange = function()
    {
    if(xmlhttp.readyState == 4)
    {
    alert(xmlhttp.responseText);
    }
    }
    xmlhttp.send(null);
    }
    function getHTTPRequestObject()
    {
    try
    {

    // Try legacy object first
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
    try

    {
    // Try IE implementation now
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(E)
    {
    xmlhttp = false;
    }
    }
    if(!xmlhttp && typeof XmlHttpRequest!= 'undefined')
    {
    // We must be using a Mozilla-based browser
    // so create a native request object now
    xmlhttp = new XmlHttpRequest();
    }
    }
    </script>
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    XmlHttpRequest hard at work!
    </div>
    </form>
    </body>
    </html>

     

    In that add the text file called TextFile.txt

    write somthing as hello world and u will see the result..

    Sunday, April 19, 2009 1:28 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 19, 2009 1:35 AM