Can someone please illuminate to me why, in the following snippet of script,
the alert statement in the try-catch gives me [object Error] ? The file
'http://localhost:1222/roomx1/getdata.php' truly does exist. I'm really lost
here and would appreciate anyone's good eye. Thanks, Ike
if(typeof window.ActiveXObject != 'undefined'){
req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange=processReqChange;
}else{
req = new XMLHttpRequest();
req.onload=processReqChange;
}
try{
req.open('GET', 'http://localhost:1222/roomx1/getdata.php',true);
}catch(e){
alert(e);
} 7 22097
Several points to note:
-You should point out which browser(s) you test in
-As far as I am aware, you should be using onreadystatechange for the
XMLHttpRequest object as well
-If you were getting the <current> page from a normal http request
( http://localhost/path), note that in most implementations, you cannot
change port to something else.
In FireFox, simply re-stating the protocol and host (even unchanged)
will result in a permission denied error.
In IE, you may or may not be able to change ports, but that's a
security relaxation Microsoft likes adding to IE. It's not standard, do
not rely on it.
try also:
if(window.ActiveXObject) {} instead of your current code
Ike wrote: Can someone please illuminate to me why, in the following snippet of script, the alert statement in the try-catch gives me [object Error] ? The file 'http://localhost:1222/roomx1/getdata.php' truly does exist.
There is the problem: It is not a file, it is a resource, retrieved via
HTTP. And as such, accesses to it are subject to the Same Origin Policy.
That might be relevant here, because if the protocol, second-level domain,
or port address are different from the ones of the accessing resource, it
cannot work without further privileges. Search the archives.
[...] if(typeof window.ActiveXObject != 'undefined'){
This will be true in IE on Windows, Netscape on Windows, and Gecko-based UAs
with the ActiveX plugin.
req = new ActiveXObject("Microsoft.XMLHTTP");
This will fail in Netscape on Windows, and Gecko-based UAs with the ActiveX
plugin. You do not handle the exception, so the script will break.
req.onreadystatechange=processReqChange; }else{ req = new XMLHttpRequest(); req.onload=processReqChange;
^^^^^^^^^^
Nonsense.
} try{
You do exception handling in the wrong place.
req.open('GET', 'http://localhost:1222/roomx1/getdata.php',true); }catch(e){ alert(e); }
Should be
// global context
var _global = this;
function isMethod(a)
{
var t;
return (a && ((t = typeof a) == 'function' || t == 'object'));
}
// anywhere
var req;
if (isMethod(_global.XMLHttpRequest))
{
req = new XMLHttpRequest();
}
else if (isMethod(_global.ActiveXObject))
{
try
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
// maybe you want to try other things here
}
}
if (req)
{
// exception handling only for debugging purposes
try
{
req.open('GET', 'http://localhost:1222/roomx1/getdata.php');
req.onreadystatechange = processReqChange;
}
catch (e)
{
alert(e.name);
}
}
PointedEars
AndrewTK wrote: Several points to note:
-You should point out which browser(s) you test in
Full ACK
try also: if(window.ActiveXObject) {} instead of your current code
Nonsense.
BTW:
- You should quote the minimum of what you are replying to.
PointedEars
Thanks Andrew, -If you were getting the <current> page from a normal http request (http://localhost/path), note that in most implementations, you cannot change port to something else. In FireFox, simply re-stating the protocol and host (even unchanged) will result in a permission denied error. In IE, you may or may not be able to change ports, but that's a security relaxation Microsoft likes adding to IE. It's not standard, do not rely on it.
Yes, that was the problem, by-and-large. But I have other problems here, as
pointed out in the other posts in this thread. I have taken an example of
what I wish to do from w3schools, amended it, and am posting it under a
different thread with a few (new) questions regarding this, -Ike
Thank you, Thomas, for your comment to my post as well.
As a return comment to you: if(typeof window.ActiveXObject != 'undefined')
Should never work as 'undefined' is never returned by an undefined
object. 'undefined' is a string. myvar == 'undefined' will only return
true if myvar contains the string "undefined". I should have caught
that one initially, admitted.
if(typeof window.ActiveXObject != undefined)
Should not work either, as undefined is not a value. As of recent
browser implementations, however, it does, so that would be a valid
check. if(window.ActiveXObject) {} instead of your current code
Nonsense.
^ ^ ^ ^ ^
That's rude and uncalled for. Firstly, for its unduly dismissive
pretentiousness, secondly because you are wrong. That's always been the
way to check for undefinedness. Try:
// ===
function func(arg) {
if(arg) {alert(arg);}
else {alert("No arg passed "+arg);}
}
func("hello");
func();
// ===
I will urge you to keep future messages polite. People post here for
advice. If you disagree, say so, and say why.
AndrewTK wrote: Thank you, Thomas, for your comment to my post as well.
It would have been appreciated more if you had learned how to quote.
Please provide attribution of quoted material next time.
As a return comment to you:
if(typeof window.ActiveXObject != 'undefined') Should never work as 'undefined' is never returned by an undefined object.
Nonsense.
'undefined' is a string.
And a `typeof' operation evaluates to a string. It evaluates to
"undefined" if there is no such property or the property value is
`undefined'.
myvar == 'undefined' will only return true if myvar contains the string "undefined".
`typeof' takes precedence over `=='.
I should have caught that one initially, admitted.
Pardon?
if(typeof window.ActiveXObject != undefined)
Should not work either, as undefined is not a value.
Nonsense. It does not work because a `typeof' operation evaluates to
a string value, and `undefined' evaluates to none. `undefined' is a
property of the Global Object that has `undefined', the sole value of
the Undefined type, as its value.
As of recent browser implementations, however, it does, so that would be a valid check.
No, it will not. And it would fail if the Global Object had no such
property, which is why I did not use it. if(window.ActiveXObject) {} instead of your current code
Nonsense.
^ ^ ^ ^ ^ That's rude and uncalled for. Firstly, for its unduly dismissive pretentiousness,
It is but hard fact that you are unwilling to accept. Your problem.
secondly because you are wrong. That's always been the way to check for undefinedness.
Nonsense.
Whether it is defined or not does not matter. Whether it can be called or
not does matter. However, using a type-converting test instead of a
`typeof' test evaluates the property value and so causes a warning. Less
efficient, and unnecessary, considering that `typeof' is supported since
JavaScript 1.1, JScript 1.0, and ECMAScript Edition 1.
PointedEars
Thomas 'PointedEars' Lahn <Po*********@web.de> writes: AndrewTK wrote: Nonsense. ^ ^ ^ ^ ^ That's rude and uncalled for. Firstly, for its unduly dismissive pretentiousness,
It is but hard fact that you are unwilling to accept.
The two are not mutually exclusive.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.' This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Pkpatel |
last post by:
Hi,
I keep getting this error every time I try to load
crystalreportviewer on a webform with a dataset.
Here is the error:
--------------------------------------------------------
Server...
|
by: Nithi Gurusamy |
last post by:
Dear Group:
I have a COM object developed in VB. It makes ADODB calls. When it fails it
Raise Error. I am using the COM object in my ASP using Server.CreateObject.
Whenever a function call fails...
|
by: Keith Rowe |
last post by:
Hello,
I am trying to reference a Shockwave Flash Object on a vb code behind page
in an ASP.NET project and I receive the following error:
Guid should contain 32 digits with 4 dashes...
|
by: mcmg |
last post by:
Hi,
I have an asp app that works fine on a windows xp machine but does not work
on a windows 2000 server.
I have the following code in my global.asa:
<OBJECT RUNAT=Server
SCOPE=SESSION...
|
by: Roby Eisenbraun Martins |
last post by:
Hi,
My name is Roby Eisenbraun Martins, I am a C++, VB and NET developer.
I am working with a NET 2002 project right now and I am receiving this
uncommon "OutOfMemory" error message when I try...
|
by: Dirk Försterling |
last post by:
Hi all,
a few days ago, I upgraded from PostgreSQL 7.2.1 to 7.4, following
the instructions in the INSTALL file, including dump and restore.
All this worked fine without any error (message).
...
|
by: Roman |
last post by:
I'm trying to create the form which would allow data entry
to the Client table, as well as modification and deletion
of existing data rows. For some reason the DataGrid part
of functionality stops...
|
by: blash |
last post by:
Can someone help me? I really don't have a clue.
My company staff told me they often got such error: "Object reference
not set to an instance of an object." when they are in search result
page...
|
by: J. Askey |
last post by:
I am implementing a web service and thought it may be a good idea to return a
more complex class (which I have called 'ServiceResponse') in order to wrap
the original return value along with two...
|
by: Moses |
last post by:
Hi All,
Is is possible to catch the error of an undefined element while
creating an object for it.
Consider we are not having an element with id indicator but we
are trying to make the object...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |