annoying javascript error

S

seanism

Hello all I am new to javascript and I am attempting to write a site in
JS / PHP to jump on the ajax band wagon. I am getting the following
error and have not been able to locate a solution for it yet. From
what I have read some people say it could have to do with xmlrequest
being busy or something like that.

Error: [Exception... "Component returned failure code: 0xc1f30001
(NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]" nsresult:
"0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: mysite
:: getImage :: line 37" data: no]
Source File: mysite
Line: 37

thanks!
 
R

Randy Webb

seanism said the following on 5/14/2006 2:04 PM:
Hello all I am new to javascript and I am attempting to write a site in
JS / PHP to jump on the ajax band wagon.

Oh geez, another one.
I am getting the following error and have not been able to locate a
solution for it yet. From what I have read some people say it could
have to do with xmlrequest being busy or something like that.

Or one of another million SWAG's one could make.
Error: [Exception... "Component returned failure code: 0xc1f30001
(NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]" nsresult:
"0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: mysite
:: getImage :: line 37" data: no]
Source File: mysite
Line: 37

My stereo doesn't work. Why?

The point being, you can't determine whats wrong with code that you
can't see.
 
S

seanism

very true indeed.

<script type="text/javascript">
<!--
var results;

function vote(user_id, v){
// Build the URL to connect to
var url = "vote_ajax.php?id=" + results[0] + "&user_id="+ user_id +
"&vote=" + v;
request.abort();
// Open a connection to the server
request.open("GET", url, true);

// Setup a function for the server to run when it's done
request.onreadystatechange = window.location.reload( true );

// Send the request
request.send(null);
}

function getImage(){
// Build the URL to connect to
var url = "image_ajax.php";
// Open a connection to the server
request.open("GET", url, true);

// Setup a function for the server to run when it's done
request.onreadystatechange = changeImage;

// Send the request
request.send(null);
}

function changeImage(){
if (request.readyState == 4) {
// Split the comma delimited response into an array
results = request.responseText.split(",");
document.getElementById('image').innerHTML = results[2];
}

}
//-->
</script>
 
S

seanism

var request = false;
try{
// Mozilla/Safari
if (window.XMLHttpRequest)
request = new XMLHttpRequest();
// IE
else if (window.ActiveXObject)
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert(e);
}
// Error

if(!request)
alert("XHR Object cannot create");
 
R

Randy Webb

seanism said the following on 5/14/2006 8:50 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

very true indeed.

Post a URL to a full sample page that displays the behavior and what
steps produce the error.
 
S

seanism

rgr that Randy. Should I reply on the top or bottom of the quoted
information? Also is there an easy way to see what threads you
started? If I goto my profile it shows some on the bottom but I was
thinking that they would make it easier then that? I starred the
articles that I started to see them on the my posts link.

as far as the site its www.stoneorbone.com right now it works because
instead of calling the getImage function I just have it do a JS refresh
of the page.
 
R

Randy Webb

seanism said the following on 5/16/2006 2:10 PM:
rgr that Randy. Should I reply on the top or bottom of the quoted
information?

What do most in this group do and what does that FAQ/Notes say with
regards to that?

Hint: Pay attention to how my reply is done.
Also is there an easy way to see what threads you started?

For me, yes. But, I don't use Google Groups. Ask a Google Groups person.
If I goto my profile it shows some on the bottom but I was
thinking that they would make it easier then that? I starred the
articles that I started to see them on the my posts link.

as far as the site its www.stoneorbone.com right now it works because
instead of calling the getImage function I just have it do a JS refresh
of the page.

Well, you know the getImage() function works properly or you would get
errors when it gets triggered onload.

All of that code looks like a hard way to do something. What exactly is
it that you are trying to do with it? Let someone vote, post the vote,
then retrieve an image? But then you split that image and only use part
of it. Why not just have the PHP return the plain HTML code you want to use?
 
T

Thomas 'PointedEars' Lahn

seanism said:
var request = false;

`request' is used as an object reference. It should be initialized
with `null' (null reference), not the boolean value `false'.

There is no need for try...catch for XMLHttpRequest, only for ActiveXObject.
In fact, using too much exception handling can prevent you from catching
your bugs.
// Mozilla/Safari
if (window.XMLHttpRequest)

You are feature-testing the mere _existence_ (to be more exact: the
_true-value_) of a property of _`window'_ ...
request = new XMLHttpRequest();

.... but you _construct_ with a _method_ of the _Global Object_.
Furthermore, you do not declare `request', and so it becomes a property of
the Global Object, /iff/ there is no other object in the scope chain where
this applies to. Both approaches are error-prone.
// IE
else if (window.ActiveXObject)
request = new ActiveXObject("Microsoft.XMLHTTP");

Same here.
}
catch (e) {
alert(e);
}

Your code style allows for improvement. For example, do not use tabs;
use spaces.
// Error

if(!request)
alert("XHR Object cannot create");

The content of those message boxes is useless to Joe User, so you better
make them debug messages only.

var _global = this;

function isMethod(a)
{
return a && /\b(function|object)\b/.test(typeof a);
}

function getImage()
{
var request = null;

if (isMethod(_global.XMLHttpRequest))
{
request = new XMLHttpRequest();
}
else if (isMethod(_global.ActiveXObject))
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
// ...
}
}

if (request)
{
// ...
}
else
{
// ...
}

return request;
}


PointedEars
 
R

Randy Webb

Thomas 'PointedEars' Lahn said the following on 5/22/2006 11:26 AM:
`request' is used as an object reference. It should be initialized
with `null' (null reference), not the boolean value `false'.

Either one satisfies the requirements of the test that is used on it.
There is no need for try...catch for XMLHttpRequest, only for ActiveXObject.
In fact, using too much exception handling can prevent you from catching
your bugs.
Absolutely.


You are feature-testing the mere _existence_ (to be more exact: the
_true-value_) of a property of _`window'_ ...


.... but you _construct_ with a _method_ of the _Global Object_.

So what?
Furthermore, you do not declare `request', and so it becomes a property of
the Global Object, /iff/ there is no other object in the scope chain where
this applies to. Both approaches are error-prone.

Now, once again, please name a browser that does not implement the
window as the Global Object. And especially a browser that supports
window.XMLHttpRequest where window isn't the Global Object.

Your ranting about window not being the Global Object gets old.
Your code style allows for improvement. For example, do not use tabs;
use spaces.

There are problems with the posting style, but the coding style is
perfectly acceptable. Code any way you want, just pretty it up to post
it to Usenet.
The content of those message boxes is useless to Joe User, so you better
make them debug messages only.

var _global = this;

Unneeded Global Variable.
function isMethod(a)
{
return a && /\b(function|object)\b/.test(typeof a);
}

function getImage()
{
var request = null;

if (isMethod(_global.XMLHttpRequest))

Nonsense test.
{
request = new XMLHttpRequest();
}
else if (isMethod(_global.ActiveXObject))

Nonsense test.

But, once again, nothing you posted had anything to do with the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top