0

I was following this tutorial.

I need to use a php file's ouput in my HTML file to dynamically load images into a gallery. I call

    function setOutput()
    {
        if (httpObject.readyState == 4)
            document.getElementById('main').src = httpObject.responseText;
            alert("set output: " + httpObject.responseText);
    }

from

    function doWork() 
    {
        httpObject = getHTTPObject();
        if (httpObject != null) {
            httpObject.open("GET", "gallery.php?no=0", true);
            httpObject.send(null);
            httpObject.onreadystatechange = setOutput;
        }
    }

However, the alert returns the php file, word for word. It's probably a really stupid error, but I can't seem to find it.

The php file:

<?php

    if (isset($_GET['no'])) {
        $no = $_GET['no'];
        if ($no <= 10 && $no >1) {
            $xml = simplexml_load_file('gallery.xml');
            echo "images/" . $xml->image[$no]->src;
        }
        else die("Number isn't between 1 and 10");
    }
    else die("No number set.");

?>

2 Answers 2

3

If the alert is returning the contents of the PHP file instead of the results of executing it, then the server is not executing it.

Test by accessing the URI directly (instead of going via JavaScript).

You probably need to configure PHP support on the server.

Sign up to request clarification or add additional context in comments.

2 Comments

Outputting a file directly from PHP would need the right header too, in case of a image, something like: header('Content-type: image/jpg'); The avaiable content-types are here: it.wikipedia.org/wiki/Wikipedia:Elenchi_generati_offline/…
Thanks, just had to configure the server.
0

Your Server doesn't serve/parse PHP files! You could test your JavaScript code by setting the content of gallery.php to the HTML code you want to receive.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.