The basic problem of Ajax

I have test.html, createXHR.js and ajax.jsp files in the Tomcat project directory

The test.html code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<script type = "text/javascript" src = "createXHR.js"></script>
</head>
<body>

<script type = "text/javascript">
	var xhr = createXHR();
	xhr.open("get", "http://localhost:8081/myApp/ajax.jsp", false);
	xhr.send(null);

if ((xhr.status >= 200 && xhr.status) || xhr.status == 304)
{
	alert("Success!!!" + xhr.status + xhr.responseText);
}
else
{
	alert("FAILURE" + xhr.status);
}
	</script>
</body>
</html>



The createXHR.js code is as follows:
	function createXHR()
{
	var arrVersion = new Array
	(
		"MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0", 
		"MSXML2.XMLHTTP.2.6",
		"Microsoft.XMLHTTP",
		"MSXML.XMLHTTP"
	);

	for (var i = 0; i <arrVersion.length; i++)
	{
		try
		{
			return (new ActiveXObject(arrVersion[i]));
		}
		catch (e)
		{

		}
	}

	if (window.XMLHttpRequest)
		return new XMLHttpRequest();

	return null;
}


Ajax.jsp is as follows:
<%@ page contentType = "text/html;charset=GB2312" %>

<html>
	<body>
		HELLO!!!I am welcome!!!
	</body>
</html>


If I directly double-click to open test.html, Firefox firebug will be in error.:

NS_ERROR_FAILURE: Failure
[error] this interrupt

return (new ActiveXObject(arrVersion[i]));
And through the URL input method in Firefox access can be normal operation.

While the IE8 two ways can be normal operation,
Why Firefox will appear this kind of circumstance?

When I put the open inside the URL http:// delete, do not run, why?

And the address bar Firefox I don't lose http:// can also, but the IE must lose, is it right? Firefox will automatically fill?

Just contact Ajax, basic knowledge of the network is not solid, more problems, a word may also not too appropriate, O master answer

Started by Karida at November 15, 2016 - 7:45 PM

test.html, The createXHR.js and ajax.jsp files
This is in the same project.
With no front: http://localhost:8081/myApp/
Direct write your: ajax.jsp
On the line.
If you must add a: xhr.readyState = = 4 the conditions.

Posted by Wilbur at November 19, 2016 - 8:00 PM

Thank you for your reply, I tried to say yes, but I want to know the answers to the questions above me.,

Posted by Karida at November 28, 2016 - 8:53 PM

Double click the run time file protocol access, your address is http:// this access cross domain, cross domain in Firefox will be in error.

IE created by ACX XHR object local test [click access or directly into the browser] can cross domain, using XMLHttpRequest to create the [ie7+] so wrong

Posted by Thomas at December 11, 2016 - 9:21 PM

I found a problem......
I use XMLHttpRequest objects, namely the code as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type = "text/javascript" src = "createXHR.js"></script>
</head>
<body>

<script type = "text/javascript">
var xhr = new XMLHttpRequest();
xhr.open("get", "http://localhost:8081/myApp/ajax.jsp", false);
xhr.send(null);

if ((xhr.status >= 200 && xhr.status <300) || xhr.status == 304)
{
alert("Success!!!" + xhr.status + xhr.responseText);
}
else
{
alert("FAILURE" + xhr.status);
}
</script>
</body>
</html>

1, In IE8, click and enter URL as the normal operation can,

2, When I put my open URL into ajax.jsp, IE8 by double clicking the way is wrong, the input URL mode operation,

1 is it right? That can cross domain with the browser? Rather than with what object?
The 2 is how to return a responsibility?

Posted by Karida at December 23, 2016 - 10:14 PM

Ie when you create a XMLHttpRequest can you run? XMLHttpRequest local test in IE will report access is denied access denied error, strongly suspect that you configured the browser.

1, Cross domain is a.com Ajax cannot access b.com pages, wrong. The problem is your browser security settings

2, If it is ACX to create, access to 1.jsp the file as txt to handle the return directly to the source code, should not be wrong.

Posted by Thomas at December 26, 2016 - 10:29 PM