AJAX app will not make call on Safari and FireFox, works fine on Internet Explorer, any ideas?

J

JDeats

From my development envrionment (i.e. a single WinXP notebook PC) I
have a basic AJAX application that is making the call to a Windows
Form page that just returns the request back to the AJAX client from
the JavaScript HttpXMLRequest


protected void Page_Load(object sender, EventArgs e)
{
string txt = "";
string input = null;
StreamReader sr = new StreamReader(Request.InputStream);
while ((input = sr.ReadLine()) != null)
{
txt += input;
input = null;
}

sr.Close();
sr.Dispose();


Response.Write(txt);
Response.End();

}

In the onreadystatechange event, once the request is returned I am
performing a simple JavaScript alert() to display back the response.
This works fine from IE when it's calling a local server either IIS or
from VS.NET 2005's ASP.NET development Server on port 2160. However
if I try to make the call to either of these servers from FireFox or
Safari it appears the call to HttpXMLRequest never goes through.

I understand there is a cross-domain restriction on HttpXMLRequest
calls in Safari and FireFox that is handled differently in IE, I
suspect this has something to do with the problem.... Any advice?
 
B

bruce barker

ie will also enforce cross doamain, unless the source is trusted. often
in dev, the html source is trusted, where it will not be from a hosted
server. then IE will act like forefox and safari

-- bruce (sqlwork.com)
 
J

JDeats

ie will also enforce cross doamain, unless the source is trusted. often
in dev, the html source is trusted, where it will not be from a hosted
server. then IE will act like forefox and safari

-- bruce (sqlwork.com)

Bruce,

Thanks for your help.

So I guess my question is: how does the cross-domain restriction
effect non-IE browsers when you're developing and testing on
localhost. There is no domain server present in this case as I'm not
running a domain server on my XP Pro notebook where all this is
occurring, but I do need to be able to test from non-IE browsers on my
dev environment.

req.onreadystatechange = processReqChange;
req.open("POST", "SendIt.aspx", true);
alert(req.readyState); // this returns 1 on all browsers as expected,
indicating the open command was a succes
req.send("<b>data</b>");

So after the send call is made the processReqChange function gets
called.... From inside processReqChange I can test req.readyState and
it equals 4 as expected.... however if I try to get the value of
req.status an exception is thrown in FireFox, below is the code with
comments explaining what is happening at various points.

function processReqChange() {

alert("process req changed");
// this called when the page loads by IE, FireFox and Safari..... It
is called again after the req.send(...) command is issued on FireFox
and IE, but not on Safari.


if (req.readyState == 4) {
// only if "OK"

try
{
var s = req.status;
alert(s); // I can only get to this point with Internet
Explorer.

} catch (e) {
alert("failed to read status");
// this catch is always trigged from FireFox, again with
Safari this event handler methid is never even triggered after the
req.send...
}


-Jeremy
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top