i dont understand one thing.
if i want to get JSON data (key-value-pairs) from php to jquery using ajax...which of these following ones should i use?
$.get
$.post
$.getJSON
do i need to use getJSON
if i want to use json_encode
in php file? but what if i want to send with post? (there is no postJSON
)?
and one more thing:
in php file i wrote:
<?php
if($_GET['value'] == "value")
{
$array['firstname'] = 'Johnny';
$jsonstring=json_encode($array);
return $jsonstring;
}
?>
in jquery file
$.getJSON("php.php", {value: "value"}, function(data){
alert(data.firstname);
});
why doesnt this work??:S