2 Replies - 2780 Views - Last Post: 23 November 2010 - 11:50 PM

#1 ajax_lover   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-November 10

Problem with AJAX in Mozilla

Posted 23 November 2010 - 09:03 AM

Hi all,
I am in a problem with the following ajax script. The script is written so that it should work both in IE and mozilla. It is executed successfully and returned the response text in IE but returned error code in mozilla. I am using Firefox 3.6.6 version. Thanks in advance.


<script language=javascript>
	function submitForm()
	{ 
		var req = null; 
		document.ajax.dyn.value="Started..."; 
		if (window.XMLHttpRequest)
		{
 			req = new XMLHttpRequest();
		} 
		else if (window.ActiveXObject) 
		{
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e)
			{
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
        	}

		req.onreadystatechange = function()
		{ 
			document.ajax.dyn.value="Wait server...";
			if(req.readyState == 4)
			{
				if(req.status == 200)
				{
					document.ajax.dyn.value="Received:" + req.responseText;	
				}	
				else	
				{
					document.ajax.dyn.value="Error: returned status code " + req.status + " " + req.statusText;
				}	
			} 
		}; 
		req.open("GET", "http://www.cindyruppert.com/status.txt", true); 
		req.send(null); 
	} 
	</script>


<FORM name="ajax" method="POST" action="">
		<INPUT type="BUTTON" value="Submit"  onclick="submitForm()">
		<input type="text" name="dyn" size="32" value="">		
	</FORM>


Is This A Good Question/Topic? 0
  • +

Replies To: Problem with AJAX in Mozilla

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5541
  • View blog
  • Posts: 14,543
  • Joined: 18-April 07

Re: Problem with AJAX in Mozilla

Posted 23 November 2010 - 11:07 AM

Is this script being run from your local computer or a computer on a different domain than cindyruppert.com? If so, you are running into an error because Javascript security prevents you from reaching across domains. This means if my script is running locally on my computer I can't request a file from www.dreamincode.net. If the script is being run on www.example.com I still can't request a file from www.dreamincode.net. If the script is on www.dreamincode.net then I can request the file.

IE will actually allow you to do it, but often prompts you if you have it setup to prompt (the default). If you say yes to the prompt, then it will go ahead and fetch across domains. Firefox is a little more security conscience.... as it should be.

But that is what is probably happening here. :)
Was This Post Helpful? 1
  • +
  • -

#3 ajax_lover   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-November 10

Re: Problem with AJAX in Mozilla

Posted 23 November 2010 - 11:50 PM

Thanks Martyr2.
You are right I think. As in IE I have made it(allow active content to run in files on my computer) to always allow any active content, IE is fetching the web data without showing any prompt. If I wouldn't change the setting IE would prompt me for allowing this as you mentioned. But why Mozilla has no options like that? Mozilla only able to fetch the files within the same domain. That means when I executing it in my local computer Mozilla is only able to fetch files within my local computer and when I am uploading it to any server, mozilla then able to fetch files within that domain.

Maybe mozilla has configurations in "about:config" section. But I cannot find any such option there that similar to the "allow active content to run in files on my computer" options in IE. And allowing active content always is a dangerous setting, I think. So instead of allowing it always I want to allow only that particular page where I need this setting as this is a need only for me(my mozilla browser).

Thank you Martyr2 for ensuring me the case. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1