duncanrager
duncanrager

Reputation: 247

dojo.xhrGet Returns PHP Source Code, not Text Response

The code below calls a PHP file for a true or false text result using the dojo.xhrGet method. When I load the PHP file by itself (replacing the $variable = $_GET("passedVariable"); with a hard-wired value), it correctly generates a "true" or "false" in my browser window. However, when I run the call in my larger web app, it returns the PHP source code instead of the results of my database query. Using JQuery's .get() method, I receive a XML object.

Here's the Javascript...

dojo.xhrGet({
                    url: "php/check.php",
                    handleAs: "text",
                    content: {guid: featureGuid},
                    load: function(response){
                            alert(response);
                            dojo.style(dojo.byId("photoLink"), "display", "");
                            }
                });

Here's the PHP...

<?php

$guid = $_GET["guid"];

// Connect to Database
$server = "server";     
$connectionSettings = array("Database"=>"db", "UID"=>"uid", "PWD"=>"pwd");
$connection = sqlsrv_connect($server, $connectionSettings);

if (!$connection){
    die("Failed Connection");
}

// Prepare and Execute query
$sql = "sql";
$results = sqlsrv_query($connection, $sql);

if ($results){
    $rows = sqlsrv_has_rows( $results );
    if ($rows === true) {
        header('Content-Type: text/plain');
        echo "true";
    }
    else {
        header('Content-Type: text/plain');
        echo "false";
    }
}
else{
    header('Content-Type: text/plain');
    echo "false";
}?>

Anything anybody see wrong with this?

Thanks.

Upvotes: 0

Views: 373

Answers (2)

tinyd
tinyd

Reputation: 952

I'd check the requests and responses using Firebug - check that the URLs and headers are the same when you call the URL directly from the browser as opposed to via the XHR.

Upvotes: 1

Travis Pessetto
Travis Pessetto

Reputation: 3298

I am not sure but:

  1. Try making sure that your Main App is executing PHP properly, it seems odd that JavaScript can pull the source code.

  2. Try adding: die() after echo true or echo false which will prevent it from going any further.

The reason I say to check the larger app for PHP execution is because it almost seems like the webserver is rendering the source code as html and not running it through the interpreter.

Upvotes: 0

Related Questions