•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,022 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,442 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 7122 | Replies: 9
![]() |
•
•
Join Date: Jul 2006
Posts: 66
Reputation:
Rep Power: 3
Solved Threads: 1
Hi...
I'm developing a simple script using AJAX and php to update a database...But the script is running fine on IE but not at all
on Firefox2.0.0.3....Please help me out
Here's my AJAX script
var xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="http://127.0.0.1/testminor/minor.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
I'm developing a simple script using AJAX and php to update a database...But the script is running fine on IE but not at all
on Firefox2.0.0.3....Please help me out
Here's my AJAX script
var xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="http://127.0.0.1/testminor/minor.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation:
Rep Power: 5
Solved Threads: 47
Are you getting any specific errors in the firefox error console? I believe FF will reject XMLHTTP connections to pages that aren't on the same domain that the script runs from; I imagine that's amplified by the fact you're trying to connect to 127.0.0.1... Easiest way to get around this is to use relative/server absolute URLS in XMLHTTP opens..
http://developer.mozilla.org/en/docs...etting_Started
http://developer.mozilla.org/en/docs...etting_Started
•
•
•
•
Originally Posted by Mozilla
As a security feature, you cannot call pages on 3rd-party domains. Be sure to use the exact domain name on all of your pages or you will get a 'permission denied' error when you call open(). A common pitfall is accessing your site by domain.tld, but attempting to call pages with www.domain.tld.
If it only works in Internet Explorer; it doesn't work.
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation:
Rep Power: 5
Solved Threads: 47
•
•
Join Date: Jul 2006
Posts: 66
Reputation:
Rep Power: 3
Solved Threads: 1
I'm not getting any errors....
Just no output + no database update as I'm getting through IE
My html and php scripts are given below
These are just simple scripts....+
I wanna ask If firefox needs any plugin for AJAX
******************
<html>
<head>
<script src="clienthint1.js" language="javascript"></script>
</head>
<body>
<form name="form1">
<input type="text" name="ajaxtest">
<img height="30" width="50"src="Water lilies.jpg" onClick="showUser(document.form1.ajaxtest.value)">
</form>
<p>
<div id="txtHint"><b>User info will be listed here.</b></div>
</p>
</body>
</html>
*****************
And my php script is...
***********
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', 'anchal');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("goonj", $con)
or die("Database not selected");
$sql="INSERT into users(name) values('$q')";
mysql_query($sql)
or die("Error");
echo "<table border='1'>
<tr>
<th>DATABASE UPDATED</th>
</tr>";
echo "</table>";
mysql_close($con);
?>
****************
Just no output + no database update as I'm getting through IE
My html and php scripts are given below
These are just simple scripts....+
I wanna ask If firefox needs any plugin for AJAX
******************
<html>
<head>
<script src="clienthint1.js" language="javascript"></script>
</head>
<body>
<form name="form1">
<input type="text" name="ajaxtest">
<img height="30" width="50"src="Water lilies.jpg" onClick="showUser(document.form1.ajaxtest.value)">
</form>
<p>
<div id="txtHint"><b>User info will be listed here.</b></div>
</p>
</body>
</html>
*****************
And my php script is...
***********
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', 'anchal');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("goonj", $con)
or die("Database not selected");
$sql="INSERT into users(name) values('$q')";
mysql_query($sql)
or die("Error");
echo "<table border='1'>
<tr>
<th>DATABASE UPDATED</th>
</tr>";
echo "</table>";
mysql_close($con);
?>
****************
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation:
Rep Power: 5
Solved Threads: 47
I ftp'd your files up to a live host. There, I arranged the files like so:
I had to change one line of your javascript:
This meets the conditions of Firefox not allowing XMLHTTP open to 3rd party hosts; I could equally have used a full URL; but I'd have had to ensure I used the exact same domain to access the page.
The result is here: http://fusiongroups.net/temp
It works for the version of Firefox I have on Windows (1.0.7); try on yours, let me know if it says 'OK' when you click the button... If it does, the XMLHTTP open is working, and this means that there may still be a problem in that the domain you're using to access the page differs from the domain referenced in the XMLHTTP open() URL.
If the page at that link doesn't work (i.e. no OK when clicking the image), I'll swap operating system and have a look on the latest Firefox for you.
www [folder]
|_ temp [folder]
|_ index.html (your html page)
|_ clienthint1.js ( the javascript )
|_ minor.php ( a php file that just echos 'OK', suitable for a test )var url="http://127.0.0.1/testminor/minor.php" .. changed to .. var url="minor.php"
The result is here: http://fusiongroups.net/temp
It works for the version of Firefox I have on Windows (1.0.7); try on yours, let me know if it says 'OK' when you click the button... If it does, the XMLHTTP open is working, and this means that there may still be a problem in that the domain you're using to access the page differs from the domain referenced in the XMLHTTP open() URL.
If the page at that link doesn't work (i.e. no OK when clicking the image), I'll swap operating system and have a look on the latest Firefox for you.
If it only works in Internet Explorer; it doesn't work.
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation:
Rep Power: 5
Solved Threads: 47
Try and test on a 'real server'; or make sure that you always also access the page with the Javascript directly from 127.0.0.1. Providing that you do that; you should be able to omit the 127.0.0.1 from the Javascript code (which also removes the need to change the code when you do go live).
Xampp sets up a system whereby you can access any kind of page in a folder using a http url, so you should certainly be able to make a folder structure similar to the one I did.
Xampp sets up a system whereby you can access any kind of page in a folder using a http url, so you should certainly be able to make a folder structure similar to the one I did.
If it only works in Internet Explorer; it doesn't work.
•
•
Join Date: May 2007
Posts: 20
Reputation:
Rep Power: 0
Solved Threads: 0
Himanjim, remember that you cannot connect to another domain using AJAX in Mozilla based browsers, so you can use just relative path of request like '/test/file.php'..
Join a forum for webmasters and developers
HTML Forum
HTML Forum
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
age ajax asp beta bon browser browsers business developer development echo email encryption environment firefox gecko home html ibm. news internet internet explorer 7 it leak linux memory microsoft mozilla msdn networking news office open source open-source patch phishing remote working scams security site social software sql super testing trends users vista web webmail working
- Internet Explorer is not working - Firefox is (Viruses, Spyware and other Nasties)
- Http request error when using AJAX. (JavaScript / DHTML / AJAX)
- Help re scrolling bar not working in firefox, CSS problem (HTML and CSS)
- Levyo Ajax Gallery supports Firefox 2.0.1 only?? (Software Developers' Lounge)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: "add this site to your bookmarks" in firefox
- Next Thread: Round Numbers


Linear Mode