views:

77

answers:

1

Hi all, i have been learning about javascript and using dojo. I am trying to execute a php file with dojo. My code is

 dojo.xhrGet({
  url: 'helloworld.php', 
  load: testCallback, 
  error: testError,
  content: {name: dojo.byId('name').value}
  });

for the dojo function. The php file is basically a simple script that prints the value of whats being passed in through xhrGet

<?php 
  header('Content-type: text/plain');
  print "Hello {$_GET['name']}\n";
?>

When I call this function, I get the php file displayed as text. My testCallback function is simply

function testCallback(data, ioArgs)
   {
    alert("in testCallback");
    alert(data);
   }

I cant think why this wont work as it was pulled from the dojo tutorial itself. I tested php with a file with phpinfo() in it, and it was working. Does php have to be configured to 'work' with certain ports?

+3  A: 

If you get your php file back as text your webserver is not setup to call php to handle the file. It is as simple as that.

Have you named it .php or something else (judging from the post it looks like it is called helloworld.php and in that case I wonder how your phpinfo() call could work, was it the same server?)

Fredrik
Here is the thing, I am using Aptana Studio for development work, and when I click the "compile" button, it brings me to this sitehttp://127.0.0.1:8000/Test/index.htmlIt seems that 127.0.0.1:8000 brings me to the development folder for Aptana, where Test is the project folder. When I was testing out php, I used the folder /Library/Webserver/Documents(am working on a mac) and it brought me to this address.http://127.0.0.1/test.phpAdditionally, I copied this test.php file to my dev folder. When I try to access it thru browser, I get a file not found error. Very weird.
Ying
I should mention that test.php is the file that contains a single phpinfo() call. I guess the easiest thing for me to do is to move the dev folder into /Library/Webserver/Documents, but it would be helpful to learn why it wont work in a different folder.
Ying
Knowing nothing about Aptana Studio it sounds like it comes with a built-in php enabled webserver (which you can reach on port 8000) and that your ordinary webserver is not PHP-enabled. According to the document at the following link, it seems like php comes bundled with OSX but that you have to uncomment a few things to enable it.http://www.php.net/manual/en/install.macosx.bundled.php
Fredrik
Its actually the other way around. I finally moved my stuff into the webserver on the mac, and it worked out. Thanks for all those that chipped in.
Ying
ah, same thing. Whatever you used didn't have php enabled.
Fredrik