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 22094
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: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |