tags:

views:

58

answers:

1

Hi there, im attempting to make a auto preloader via php an JSON my reason being no other preloaders suit my purposes at this time. Im developing off a WAMP installation with php version 5.3.0 an apache version 2.2.11 an using the following php code:

$rootDir =  dirname(__FILE__).'/..';
$imgdir = opendir($rootDir.'/images/');
$i=0;

while ($file = readdir($imgdir))
{
if (($file != '.') && ($file != '..'))
{
$fileList[$i] = $file;
$i++;
}
}

$json=json_encode($fileList, JSON_FORCE_OBJECT);
die($json);

My Jquery is inline/embeded at the moment (version 1.4.2) and is as follows:

$(document).ready(function(){
    $.ajax({
        type: "GET",
        url: "preload/reader.php",
        dataType: "JSON",
        success: function(data){
            alert(data);
        }
    });
});

this has the following output in an alert box; {"0":"BlueHills.jpg","1":"deagle_descr.jpg","2":"mod.jpg"}

the problem actually starts when i want to do anything else with data, the page never finishes loading like it's stuck in an infinite loop or something. Even just a simple statement like document.write(data); it the page is stuck in loading state until i hit stop in the browser. Im fairly new to JSON please help

A: 
  1. use getJSON
  2. in the callback function of getJSON, start adding tags to the DOM, but hidden by default
  3. show then new images whenever you need
Tudorizer
i replaced the above ajax with$.getJSON("preload/reader.php", function(data){ $.each(data, function(i,current){ document.write(current + "<br />"); });});but this still doesnt solve my problem that in firefox the page refuses to finish loading until i hit stop in the browser
elitepraetorian
The page not finishing to load might be from somewhere else. Check all the requests that are being made in Firebug's Console.
Tudorizer
by checking in firebug i assume u mean opening the net tab an see all the requests. Well ur outta luck it shows absolutely nothing i know it's working cuz cuz i ran firebug on WAMP's localhost page an it all popped up.For ina's benefit: Im trying to encode a php array to a JSON Object pass it to JQuery parse the results into a Javascript Array, loop through the javascript array an preload all the images.
elitepraetorian
The only thing i can be sure of is it has something to do with AJAX an XHR as if i remove all actions after after the JSON object has been loaded the script loads an everything works fine.
elitepraetorian
No, I literary mean Firebug's Console. The 1st tab. Here's a screenshot: http://i.imgur.com/FTto1.png. It shows all the AJAX calls made and you'll see when they finish. ina requested a code snippet, not an explanation.
Tudorizer
I am not here to run error checking for u, i am here because i have tried everything i know and still cant solve this dilema. Maybe i wasn't clear enough before, absolutely nothing happens in Firebug console tabs or other wise. And don't tell me to reinstall it cuz i know it works fine already it's on a clean profile with nothing else on there. I'm getting frustrated here please i need a solution not advice on error checking methodologies. Oh an im back to using my original code that i posted here since .getJSON is just an abbreviated form of it.
elitepraetorian
Check your attitude. The code you pasted above seems ok, but the lack for AJAX request in the Console is a sign. Paste the code you're running when the browser doesn't stop loading. You mention the alert() is ok, so it's something else.
Tudorizer
I apologize i was frustrated so i took some time off and did some other work for a client in joomla, now im back on the case. I have uploaded screen captures to photobucket album of the firebug console when using an alert:http://s856.photobucket.com/albums/ab126/Ve9a/Errors/I shall endeavor to soon make a video using camstudio to show u exactly what happens when i try doing something else with the code
elitepraetorian