try:
<?php
header('Content-Type: application/json');
$a = array('data' => 'Hello');
echo json_encode($a);
exit;
?>
hielo
Veteran Poster
1,131 posts since Dec 2007
Reputation Points: 116
Solved Threads: 247
Skill Endorsements: 0
What troubleshooting steps have you taken? Do you know for a fact that the getCityAndState() function is called? If yes, does it make it INTO the if clause?
If yes, is the browser (as a whole) refreshing after the function is called?
If the problem persists, try installing Firebug for Firefox. Load your page. Enabled/Launch Firebug (by clicking on the "grayed-out" bug). Then click on the "Net" tab. Once your function is called/executed, you should see the out going JSON ajax request and its result. You need to verify that the request is in fact going to the correct url and the browser successfully contacts the server.
hielo
Veteran Poster
1,131 posts since Dec 2007
Reputation Points: 116
Solved Threads: 247
Skill Endorsements: 0
3. The browser is not refreshed after the function is called but should it have to be since it's just sending an alert?
No, it shouldn't, but it is possible - depending on how you call that function. My question was meant to figure out what else might be on that page of yours since you haven't disclosed much. In your case, you would want the browser to NOT refresh after the function executes. Based on your responses, it seems like you are OK on this regard, so we'll just have to see what Firebug "reports".
hielo
Veteran Poster
1,131 posts since Dec 2007
Reputation Points: 116
Solved Threads: 247
Skill Endorsements: 0
If you clicked on the "Net" tab of Firebug, you would be able to see the URL the request was sent to. Click on the url. You should see a "Response" tab. This should reveal exactly what the server sends back.
hielo
Veteran Poster
1,131 posts since Dec 2007
Reputation Points: 116
Solved Threads: 247
Skill Endorsements: 0
It's sending back the entire file
If I understood you correctly, it is sending back the entire PHP code (instead of what just "Hello"). If that is the case, it typically means that the server is not configured to execute php files. You need to search the internet for articles on how to install PHP for your particular server (IIS, Apache, etc)
hielo
Veteran Poster
1,131 posts since Dec 2007
Reputation Points: 116
Solved Threads: 247
Skill Endorsements: 0
If that is the case, it typically means that the server is not configured to execute php files.
Or the file extension is wrong. Typically only .php files are sent to the php engine, but potentially any other extension. For Apache, this is established in httpd.conf.
Airshow
Airshow
WiFi Lounge Lizard
2,782 posts since Apr 2009
Reputation Points: 370
Solved Threads: 388
Skill Endorsements: 9