I'm new to JSON/jQuery, and I'm trying various JSON-AJAX examples. Unfortunately, my simple code doesn't seem to be working.
Here is my JS/jQuery in testjs.js:
$(document).ready(function(){
$("#radio").click(function () {
$.getJSON("testphp.php", { testtest: 'blah' }, function(data){
alert(data.response);
});
});
});
and here is my PHP in testphp.php:
<?
if(isset($_GET['testtest'])) {
$arr = array('response'=>'error');
echo json_encode($arr);
}
?>
<HTML>
<HEAD></HEAD>
<BODY>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="testjs.js"></script>
<input id="radio" type="radio" name="group1" value="radio"> radio<br>
</BODY>
</HTML>
When I load testphp.php in my browser, in firebug, I notice that the array is properly returned as {"response":"error"} after I click on the radio button. However, the alert doesn't show up at all...
I've also tried following other similar examples solved here (such as this one: http://stackoverflow.com/questions/1261747/how-to-get-json-response-into-variable-from-a-jquery-script), but these correct solutions also don't produce an alert for me either. I must be doing something really wrong...
Any thoughts are much appreciated. Thanks!