By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,262 Members | 2,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,262 IT Pros & Developers. It's quick & easy.

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

P: n/a
>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?

Sep 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)

JDeats wrote:
>>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?
Sep 11 '07 #2

P: n/a
On Sep 11, 2:44 pm, bruce barker <nos...@nospam.comwrote:
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

Sep 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.