ajax call to php problem
#1
Posted 19 December 2010 - 11:00 PM
I am currently working on linux env.
I have PHP, JS and MySQL.
I am exploring ajax to use.
I tried w3shools and the example was working fine with windows.. please see link:
http://www.w3schools...ax_database.asp
However, this same example does not work in my firefox browser in linux. I am currently on VMware.
I tried this code because my code also does not work when httpRequest calls my php file.
Can you help me whats wrong with this please ?
thanks.
I tried calling PHP without using xmlhttprequest in linux and it was working fine.
I dont know whats wrong...when i use async call it does not work.
thanks much,
tinks
#2
Posted 20 December 2010 - 11:36 PM
#3
Posted 21 December 2010 - 08:12 PM
Could you provide a link to your code on the web so we can play with it and see what's going wrong?
hi,
its basically just this example i am trying out..
http://www.w3schools...ax_database.asp
i just modified it a bit for my local config..
im attaching the two files (sample.html; getuser.php)
thanks a lot,
tinks
Attached Files
#4
Posted 21 December 2010 - 09:43 PM
i installed the firebug and it says:
uncaught exception: [Exception... "Component returned failure code: 0x805e000a [nsIXMLHttpRequest.open]" nsresult: "0x805e000a (<unknown>)" location: "JS frame :: file:///C:/wamp/www/sample.html :: showUser :: line 32" data: no]
i read about this error and said something about AdBlock..i checked my add-ons and i dont even have adBlock installed..
what could possibly be wrong. im really stuck with this..
thanks
#5
Posted 22 December 2010 - 12:11 AM
AJAX requests aren't allowed from "local files", you need to run them from a server. So make sure wamp is running, you're using 'localhost' as your domain, and you should be good. You'll also need to change the AJAX request url inside of sample.html to refer to root instead of your c: drive.
#6
Posted 22 December 2010 - 12:56 AM
thanks a lot. instead of just writing the filename since they are on the same location, I
added http://localhost/filename.php, it can now open the php file that ajax is calling..thanks a lot.
however, i still have a problem with the result of the query, firebug gives out this error:
-------------------------------------------------------
Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>C:\wamp\www\getuser.php
-----------------
this is the whole php file:
<?php$q=$_GET["q"];$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("gdg", $con);$sql="SELECT * FROM useraccount WHERE id = '".$q."'";$result = mysql_query($sql);echo "<table border='1'>
<tr>
<th>UserID</th>
<th>Name</th>
</tr>";(it says the error is here--->)while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['userID'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";mysql_close($con);
?>
why is it not allowed?
thanks a lot for the help,
tinks
#7
Posted 23 December 2010 - 12:16 AM
See: http://www.pixel2lif...showtopic=36853 for debugging tips.
#8
Posted 23 December 2010 - 05:29 PM
$result = mysql_query("SELECT * FROM useraccount WHERE id = '$q'");
That error you're receiving is telling you that there is a problem with your $result query. Make sure that the table name that you're selecting the information from is the correct table name as well.
Edited by JoeyMagz, 23 December 2010 - 05:30 PM.
#9
Posted 28 December 2010 - 04:39 PM
Since you brought up the issue though, the issue could be that he doesn't have backticks around the field names in the query. Unless he posts the results of what he gets from the link i posted, i can't say for sure though.
#10
Posted 28 December 2010 - 05:34 PM
<?php $result = @mysql_query("SELECT * FROM blah WHERE username = ' ".$username." ' ");I only put the spaces there to show I had the single quotes.
I have to instead do queries like this:
<?php $result = @mysql_query("SELECT * FROM blah WHERE username = '$username'");
It's a very strange issue and it took me a while to figure out the first time I ran into the problem. Another problem I have when running a webserverr on my computer is when I try something like this:
<?php @mysql_query("INSERT INTO blah VALUES($one, $two, $three, $four)");
I am instead forced to do this:
<?php @mysql_query("INSERT INTO blah VALUES(\"$one\", \"$two\", \"$three\", \"$four\")");
#11
Posted 03 January 2011 - 03:51 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users