473,811 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlHttpRequest

Gaz
In Internet Explorer 6 I'm having a problem with the httprequest
object. I use it to call a webservice and display the result in the
readystate event handler. This works the first time I call it but
subsequently the readystate event handler function is never called, or
the event itself is never fired.

The same code works fine in Firefox. Changed it around a lot to no
effect Can anyone help?

I'm not supposed to create a new XmlHttpRequest object every time I
want to call a remote procedure am I?

Hope you don't mind the long post but here's the code it's simple
enough:

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>

</head>

<script type="text/javascript">

//initiates the XMLHttpRequest object
//as found here: http://www.webpasties.com/xmlHttpRequest
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_vers ion >= 5)
try {
xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
} catch (e) {
try {
xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
try {
xmlhttp = new XMLHttpRequest( );
} catch (e) {
xmlhttp = false;
}
}
alert("instanti ated");
return xmlhttp;
}

var Request = getHTTPObject() ;

function GetTreeOutput()
{
try
{
if( Request != null)
{
if (Request.readyS tate == 4 || Request.readySt ate == 0)
{
var sUrl = "http://itsopt-15/webgame/Service1.asmx/HelloWorld";

Request.onready statechange = GetTreeOutput_R esponse;

Request.open("P OST", sUrl, true);

Request.send(nu ll);
}
}
else
{
}
}
catch( e)
{
}
}

function GetTreeOutput_R esponse()
{
try
{
if( Request.readySt ate == 4)
{
if( Request.status == 200)
{
document.getEle mentById( "test").innerHT ML = Request.respons eText;
}
else
{
}
}
}
catch(e)
{
}
}
</script>

<body>

<input type="button" value="One" onclick="javasc ript:GetTreeOut put();"
/>
<input type="button" value="two" onclick="javasc ript:GetTreeOut put();"
/>
<input type="button" value="Three"
onclick="javasc ript:GetTreeOut put();" />

<div id="test" style="border: 1px solid Black; background-color: #ddf;
color: #003;">
</div>

</body>
</html>
Jul 23 '05 #1
20 5058


Gaz wrote:

var sUrl = "http://itsopt-15/webgame/Service1.asmx/HelloWorld";

Request.onready statechange = GetTreeOutput_R esponse;

Request.open("P OST", sUrl, true);


Try whether setting onreadystatecha nge after the open call improves things.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

Thanks that was the problem.. Cheers.

Jul 23 '05 #3
Hello Gaz,

thanks for that helpful code snippet.

A small nitpicking though:

Gaz wrote:
<input type="button" value="One" onclick="javasc ript:GetTreeOut put();"/>


I think, you should leave the "javascript :" from the onlick handler. It is
not needed or rather is is incorrect to place it there because only
javascript code is allowed, as I know.

Cheers
Daniel Kabs
Germany

Jul 23 '05 #4
Hello Martin,
var sUrl = "http://itsopt-15/webgame/Service1.asmx/HelloWorld";
Request.onready statechange = GetTreeOutput_R esponse;
Request.open("P OST", sUrl, true);


If I change the request URL to a different host than the one I fetched the
HTML page from, sending the request
- Mozilla throws a "Permission denied" exception
- Internet Explorer asks me if I want to retrieve data from a foreign host.

How can I work around this?

Cheers
Daniel Kabs
Germany
Jul 23 '05 #5
Gaz wrote:
try {
xmlhttp = new XMLHttpRequest( );
} catch (e) {
xmlhttp = false;
}


In my opinion, setting xmlhttp to "false" is not a good idea, because if you
*get* the Request Object, IE can not compare it with false:
alert(Request == false)
gives an error "object does not support..."

So I'd set xmlhttp to "null" to flag an error condition (that also goes well
together with your test in GetTreeOutput() "if( Request != null)").

Cheers
Daniel Kabs
Germany

Jul 23 '05 #6


Daniel Kabs wrote:
Hello Martin,

var sUrl = "http://itsopt-15/webgame/Service1.asmx/HelloWorld";
Request.onre adystatechange = GetTreeOutput_R esponse;
Request.open ("POST", sUrl, true);

If I change the request URL to a different host than the one I fetched the
HTML page from, sending the request
- Mozilla throws a "Permission denied" exception
- Internet Explorer asks me if I want to retrieve data from a foreign host.

How can I work around this?


That is not code I have posted. You are seeing the results of the same
origin policy as it is applied to fetching XML data, with normal
settings your code loaded via HTTP is not allowed to load data from a
different server.
IE with its security zone model might allow it if the zone is configured
to ask whether the request is allowed, if you want to change that for IE
you can I think even configure it to allow to access data across domains
but that is a security risk in general.
With Mozilla in a HTTP context you would need signed script, if you load
the page with the script making the request locally from the file system
you can have the script request the privilege from the user e.g.
if (typeof netscape != 'undefined' && typeof netscape.securi ty !=
'undefined') {

netscape.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserRead');
httpRequest.ope n(...);
httpRequest.sen d(...)
}
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #7
Hello!

Martin Honnen wrote:
That is not code I have posted.
I know, but I thought you might shed light on that question and you did :-)
You are seeing the results of the same
origin policy as it is applied to fetching XML data, with normal
settings your code loaded via HTTP is not allowed to load data from a
different server.


I don't see any problem, why it could be a security risk to allow scripts to
access data across domains. Quite the contrary, I think scripts should be
allowed to gather data from different hosts, e.g. the web server, database
server, and so on.

What did I miss here?

Cheers
Daniel
Jul 23 '05 #8


Daniel Kabs wrote:

Martin Honnen wrote:
You are seeing the results of the same
origin policy as it is applied to fetching XML data, with normal
settings your code loaded via HTTP is not allowed to load data from a
different server.

I don't see any problem, why it could be a security risk to allow scripts to
access data across domains. Quite the contrary, I think scripts should be
allowed to gather data from different hosts, e.g. the web server, database
server, and so on.


It can surely be desirable and not be a security risk if a certain
script can access data from certain different servers but in general if
example.com for instance uses XML data and an XSLT stylesheet to output
its data to its users then it could be a security risk if a script from
the unrelated example.org is simply able to present the data on its own
site perhaps spoofing example.com.
The same origin policy in client-side scripting certainly for some
people prevents uses which are not doing any harm but if you want to be
able to prevent abuse then you have to make a compromise and that is in
this case a rather rigid policy as a browser can usually not decide
whether example.com and example.org would agree on data exchange between
the sites.
Mozilla for web services has tried to suggest a new model where any site
can publish a file which declares which hosts have what access but this
has not really find wide spread application as far as I know:
<http://lxr.mozilla.org/mozilla/source/extensions/webservices/docs/New_Security_Mo del.html>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #9
Daniel Kabs <da*********@gm x.de> writes:
Gaz wrote:
<input type="button" value="One" onclick="javasc ript:GetTreeOut put();"/>


I think, you should leave the "javascript :" from the onlick handler. It is
not needed or rather is is incorrect to place it there because only
javascript code is allowed, as I know.


I agree on leaving it out, but coincidentally, it is not incorrect to place
it there, merely irrelevant. The Javascript parser accepts it as a label
with the name "javascript ", as can be seen by this test code:

onclick="javasc ript:while(true ){ break javascript; }alert('Done'); "

Since the label is not used, it is simply wasted space and download
size, and should be removed.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
14100
by: Matt Kruse | last post by:
I'm aware of the circular reference memory leak problem with IE/closures. I'm not sure exactly how to resolve it in this situation. Also, Firefox appears to grow its memory size with the same code. So I'm wondering if I'm missing something? My test code is as follows: function myObj() { var req = new Object(); req.temp = 0;
21
11762
by: Joe Attardi | last post by:
Hey all! I was reading over at the IE Blog the other day http://http://blogs.msdn.com/ie/] and read some interesting, and encouraging news. According to Sunava Dutta, an IE Program Manager, starting in IE7 XMLHttpRequest will be a plain JavaScript object. It will still include the Microsoft.XMLHTTP ActiveX component for compatibility, but IMHO this is a very good shift for IE. What do you think?
13
11512
by: TLaufenberg | last post by:
I'm new to Javascript programming and I've run into a bit of a snag with making an XMLHttpRequest in the Safari browser. Actually, the request doesn't work in Firefox either but only when I use a Mac computer. IE and FireFox on a Windows based system works just fine. The problem I am having is that the XMLHttpRequest doesn't open the site that I've programmed into it. When I check the readyState it only returns 0 and never goes through the...
5
2412
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML HTTP Request object." In my haze of testing yesterday it seems that NN6.1 provides an non-functional XMLHttpRequest object and NN6.2 XMLHttpRequest object
1
25113
by: Charlie | last post by:
I am trying to make an XMLHttpRequest which violates the default "same- origin"policy in Firefox. I checked the archives and found a method that should work but it does not. Below is the test code I isolated. I set signed.applets.codebase_principal_support true and seemed to get the UniversalBrowserRead permission but then the open still failed with the same old "Permission denied to call method XMLHttpRequest.open" error. Can someone tell...
1
4036
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
1
5306
by: Tarik Monem | last post by:
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest. Can I use PHP do what I'm trying to do? Here's my code: The function mySaveFunction() is called by clicking the "Update" button, after the user changes the data which is populated in the form fields, which was retrieved via XMLHttpRequest from an XML external file. I know that...
6
2308
by: Patrick Nolan | last post by:
I'm working on cross-platform portability of some javascript. My Macintosh testing platform is rather old. It has Safari 1.3.2 and Internet Explorer 5.2. I got Safari working, but now IE is causing trouble. It chokes on this: if (window.XMLHttpRequest) nameReq = new XMLHttpRequest(); else if (window.ActiveXObject) nameReq = new ActiveXObject("Microsoft.XMLHTTP");
2
2460
by: Michael Nemtsev [MVP] | last post by:
Hello, In the current application we have several httpmodules to process pages, and we have several pages with calls directly through the XMLHttpRequest. Now the requiremens is to detect the calls through the XMLHttpRequest and apply addional actions in httpmodule for these types of call. Because they dont use ASP.NET AJAX for this I cant use ScriptManager.IsInAsyncPostBack. Everything what comes into my my how to catch these calls is...
0
9722
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10393
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6882
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.