Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts

    xmlHttpRequest, Connection not working

    hmm I keep getting this error in firefox:

    Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: myfile :: handleResponse :: line 237" data: no]
    Source File: myfile
    Line: 237

    and an "Unspecified Error" in IE, for the xmlHttpRequest object I am trying to use.

    I'm using it elsewhere but this particular instance it doesnt seem to work (while everywhere else in the same .js file it works)

    heres the code which works everywhere except in this one case, if anybody has stumbled on such a snag, please post a solution, else if anybody would like to check the source file out, ill email it. thx

    Code:
    function getServings(recipe_name) {
    	
      var url="get.jsp?serv_recipe=" + recipe_name;
      xmlHttp.open("GET", url, true);
      xmlHttp.onreadystatechange=handleResponse;
      xmlHttp.send(null);
      
      // handle processed output  
      function handleResponse(){
    	if (xmlHttp.status != 200) {
    		alert("OMFG");
    	}
        if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
          var getVal = xmlHttp.responseText;
          return getVal;
        }
      }
    }
    oh and I believe xmlHttpRequest.status is where the problem lies, not so sure though

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Quote Originally Posted by zenithwolf View Post
    oh and I believe xmlHttpRequest.status is where the problem lies, not so sure though
    To check the response status:
    Code:
      function handleResponse(){
        if (xmlHttp.readyState == 4) {
             if (xmlHttp.status == 200) {
                var getVal = xmlHttp.responseText;
                return getVal;
              } else {
                alert('Error: ' + xmlHttp.status + '\n' + xmlHttp.statusText);
              }
         }
       }
    HTTP status codes

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Error deals with the status, I talk about how to catch the error here: http://radio.javaranch.com/pascarell...345471027.html

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • Users who have thanked A1ien51 for this post:

    zenithwolf (09-05-2007)

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I tried both the solutions, but to no avail, and Alien51 I'm afraid I fail to understand how merely catching the error will solve it? And I tried to catch it, doesnt work it doesnt even let me access the status of my XHR object, for IE it gives me the unspecified error and for firefox it gives me the crazy thing Alien51 talks about... I still don't understand how I would SOLVE this problem, because as I said before, I used the same structure etc. in a few other functions to get a request to my jsp, and it works in all except this one...

  • #5
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Did you do something like this:
    Code:
    var status = "N/A";
    var statusText = "N/A";
    try{ status = xmlHttp.status;}catch(e){}
    try( statusText = xmlHttp.statusText'}catch(e){}
    alert(status + "\n" + statusText );
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • Users who have thanked A1ien51 for this post:

    zenithwolf (09-05-2007)

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    ok it seems to work in IE now (giving me stupid unspecified errors) when I turn the asynchronous off... I dont understand why it should fail to work if async is off in IE since the response is to be returned immediately like in my other functions...however this doesnt work AT ALL in firefox! need help ASAP. thx

  • #7
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    ALos catching the error will allow you to see if there actually was anything there.

    Do you have Firebug installed? www.getFirebug.com

    That will let you inspect the XHR request in more detail and see what comes back from the server.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • Users who have thanked A1ien51 for this post:

    zenithwolf (09-05-2007)

  • #8
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    hmm thanks, the error check works, but I still don't understand why...and its async again, so the problem is for the most part solved, but I have no idea why this works lol

    EDIT: never mind, you answer before I had a chance to ask

    EDIT 2: firebug is pretty neat, anyway, quick noob question: why won't it let me appendChild a hidden input field to under a td?
    Last edited by zenithwolf; 09-05-2007 at 07:51 PM.

  • #9
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    what does the code look like and what is the exact error?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #10
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    its aight i solved, thanks for your help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •