tags:

views:

50

answers:

3

Hello. I've got a webpage which needs to load some data from a database. In order to do that, I'm using jquery's $.post function, which loads a file called photoList.php, as follows:

*(photoList.php)*
<?php
include 'mysqlConnect.php';

$query = mysql_query("SELECT name FROM images");
$photoList = Array();

while ($row = mysql_fetch_assoc($query))
{
 $photoList[] = $row['name'];
}

echo json_encode($photoList);
?>


*(jquery code which **is** being executed)*
$(document).ready(function(){
var photoList;
var photoCount;

$.getJSON("photoList.php", {}, processList);

function processList(data) {
 photoList = data;
 photoCount = photoList.length;
 initialize();
}
});
*(this goes on and does some other stuff with initialize()).*

Through initialize() the data that is gotten from the database -image filenames- are supposed to be displayed in the webpage. Problem is: whenever I try it in my computer (apache, windows machine), everything works fine, images show up. When I upload my webhost (apache, linux machine), they don't, nothing shows up.

This is not the only part where it happens; I've got another, similar, code, in which I encode a javascript array to JSON and then, through ajax, send it to a php file which later decodes and uploads the data to the database. This, again, works in my computer but when I upload it, it doesn't.

I've tried checking in which part the code stops working and, at least in the last one, the array is encoded to json perfectly but then, when the php is supposed to get the data, the array shows up empty.

Any ideas? =/

A: 

Hi,

If you're using IE, try pass a random hash in the php link (current timestamp + a random 5 digit string, for example). The reason for that to happen, in case of IE, is the "so loved" cache it creates for every single file. To find out if that's the problem, open the php file directly on the browser and press F5.

yoda
Nope, I've tried with opera, chrome, firefox and ie and none is working. It doesn't seem to be a cache problem, since nothing is being showed up at all. Thanks anyways, the tip may help me in something else :)
kout
A: 

You may want to make certain that your hosting site has the php libraries compiled in that you need.

One way to test this is to allow the function to use GET parameters and test by going through the browser. See if any errors are returned on the php page.

Once you know that works, then use Firefox, with Firebug extension, and see what is being sent and received through the console tab in firebug.

Once you have more information then update your question here and it will be easier to help you.

James Black
Followed your tips and checked with Firebug what the response of the php file was; it seems that my webhost inserts a piece of random code with ads and counters in every page, and that is interfering with the json encoding. I'll check if there's a way to avoid that or else I'll have to find another webhost. Thank you very much :)
kout
Glad you figured it out. Firebug is something I can't imagine doing web development without.
James Black
A: 

Very very dangerous unfiltered mysql aside. Your trouble is on the php side not the jQuery side. Some server implementations have strange ways of loading the POST and GET variables, I believe this is the case. Your Php script simply can't access the data being sent to it. Try to do a full echo of the data being received by the Php script, and capture what is being sent using Fiddler.

whatnick