0

So,

I'm applying AJAX to my whole website. All was/is working fine except for 1 piece of code. Every time i try to open this page it'll show me an internal error (500), but the code is fine ( when i try to open it without AJAX it shows completely fine.

This is the code i'm using to call the ajax function:

    function liveaddproduct() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else {  // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById("content").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","modules/pages/ajax/add-product.php",  true);
    xmlhttp.send();        
}

This is the code what isn't working when using ajax:

//These two lines work fine but as soon as the foreach starts it'll show the internal error
$dir = "media/productfotos/";
                        $folder = glob($dir . '*.{*}', GLOB_ONLYDIR);

                        foreach (new DirectoryIterator($dir) as $img){
                            if ($img->isDir() && !$img->isDot()) {
                                echo "<option value=" . $img . ">" . $img . "</option>";
                            }
                        }
Xolus
  • 1
  • 2
  • 1
    A "500 Internal Server Error" status code (or a blank page) means that your script is throwing an error but you haven't configured PHP to display error messages. That's something you need to fix before you go further; it's impossible to code properly without the aid of error messages. Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). The error reporting thumb rule is: show in development, log in production. – Álvaro González Feb 23 '16 at 15:15
  • @ÁlvaroGonzález I turned it on but the page isn't showing any error, as i said my script was working fine until i stared using AJAX. however finding directories using scandir($dir) works, why does this work and DirectoryIterator not? – Xolus Feb 23 '16 at 15:30

0 Answers0