I am using jQuery's $.post function to retrieve some data from a php file, but the returned data does not seem to be showing? Here is what I have got.
Javascript Code:
$(document).ready(function(){
$("#import").click(function(){
//This code works when uncommented, used for debugging.
/*var x = "tester";
$('input[name=title]').val(x);*/
$.post("import.php", function(data){
$('input[name=title]').empty().val(data.name); // John
$('input[name=subtitle]').empty().val(data.time); // 2pm
}, "json");
});
});
PHP import.php Code:
<?php
$my_array = array("name"=>"John","time"=>"2pm");
echo json_encode($my_array);
?>
Is there something silly I've missed out, or have I gone about this incorrectly. I'm fairly new to javascript/jquery.