Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2007, 12:43 AM   PM User | #1
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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
zenithwolf is offline   Reply With Quote
Old 09-05-2007, 11:57 AM   PM User | #2
rwedge
Regular Coder

 
Join Date: Feb 2005
Posts: 679
Thanks: 0
Thanked 16 Times in 15 Posts
rwedge is on a distinguished road
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
rwedge is offline   Reply With Quote
Old 09-05-2007, 02:53 PM   PM User | #3
A1ien51
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
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Users who have thanked A1ien51 for this post:
zenithwolf (09-05-2007)
Old 09-05-2007, 04:44 PM   PM User | #4
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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...
zenithwolf is offline   Reply With Quote
Old 09-05-2007, 07:31 PM   PM User | #5
A1ien51
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
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Users who have thanked A1ien51 for this post:
zenithwolf (09-05-2007)
Old 09-05-2007, 07:32 PM   PM User | #6
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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
zenithwolf is offline   Reply With Quote
Old 09-05-2007, 07:35 PM   PM User | #7
A1ien51
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
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Users who have thanked A1ien51 for this post:
zenithwolf (09-05-2007)
Old 09-05-2007, 07:44 PM   PM User | #8
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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..
zenithwolf is offline   Reply With Quote
Old 09-05-2007, 10:49 PM   PM User | #9
A1ien51
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
A1ien51 will become famous soon enough
what does the code look like and what is the exact error?

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 09-06-2007, 05:09 AM   PM User | #10
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
its aight i solved, thanks for your help
zenithwolf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:25 PM.


Advertisement
Log in to turn off these ads.