problem with firefox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: problem with firefox

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Location
    algiers, Algeria
    Posts
    126

    problem with firefox

    Hi, this code work with IE but it does'nt work with firefox i dont know why i use firefox 1.5.0.7.
    Code:
    <html>
    <head>
    <title>Index.html</title>
    <script language="JavaScript" type="text/javascript">
    var request;
    var queryString;
    
    function setQueryString()
    {
    	queryString="";
    	var frm = document.forms[0];
    	var numberElements =  frm.elements.length;
    	//window.document.write(frm.elements.length);
    	for(var i = 0; i < numberElements-1;++i)
    	{
    		//window.document.writeln(frm.elements[i].name+"<br>");
    		if(i!=numberElements-1)
    		{
    			queryString += frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value)+"&";
    		}
    		else//dernier formulaire
    		{
    			queryString += frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value);
    		}
    	}
    	//window.document.write(queryString);
    }
    
    function sendData()
    {
    	setQueryString();
    	var url="http://www.xxxxx.org/post.php";
    	httpRequest("POST",url,true);
    }
    
    function initReq(reqType,url,isAsynch)
    {
    	//
    	request.onreadystatechange=function()
    	{
    		//alert("init");
    		if (request.readyState == 4)
    		{
    			 if (request.status == 200)
    			 {
    					var v0=document.getElementById("ptext");
    					var v1=document.getElementById("text-p");
    					v0.value+=(request.responseText);
    					v1.innerHTML+=(request.responseText);
    			 }
    			 else
    			 {
    					alert('Un problème est survenu avec la requête.');
    			 }
    		}
    	};
    	request.open(reqType,url,isAsynch);
    	request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    	request.send(queryString);
    }
    
    function httpRequest(reqType,url,asynch)
    {
    	if(window.XMLHttpRequest)
    	{
    		request = new XMLHttpRequest();
    	}
    	else
    	{
    		if (window.ActiveXObject)
    		{
    			request=new ActiveXObject("Msxml2.XMLHTTP");
    			if(!request)
    			{
    				request=new ActiveXObject("Microsoft.XMLHTTP");
    			}
    		}
    	}
    	if(request)
    	{
    		   initReq(reqType,url,asynch);
    	}
    	else
    	{
    		   alert("Your browser does not permit the use of all of this application's features!");
    	}
    }
    </script>
    </head>
    <body>
    <div align="justify"><input type="text" id="ptext" size="200"></div>
    <h3>A Few Facts About Yourself...</h3>
    <form action="javascript:void(0)" onsubmit="sendData();return false">
    	<p>First name: <input type="text" name="firstname" size="20"></p>
    	<p>Last name: <input type="text" name="lastname" size="20"></p>
    	<p>Gender: <input type="text" name="gender" size="2"></p>
    	<p>Country of origin: <input type="text" name="country" size="20"></p>
    	<p><button type="submit">Send Data</button></p>
    </form>
    <span id="text-p"></span>
    </body>
    </html>

  2. #2
    Join Date
    Sep 2006
    Posts
    28

    Re: problem with firefox

    I found your problem
    Code:
    var url="http://www.xxxxx.org/post.php";
    Firefox tries to prevent you from sending things off the domain. Don't include the "http://servername". For instance if "post.php" was in the same folder as your ajax code, just put:
    Code:
    var url="post.php"

  3. #3
    Join Date
    Dec 2005
    Location
    algiers, Algeria
    Posts
    126

    Re: problem with firefox

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center