I want to know when will it be reasonable to pull data from a php page via ajax in form of json array.. Suppose I have this code :
$.ajax({ type: "get", url: "assets/update_cart_user_fstore.php", data: up, cache: false, success: function(r){ $(#item).html(r); }, }); and in PHP page I am echoing a variable
$hello = "I am code!"; echo $hello; And with JSON
$.ajax({ type: "get", url: "assets/update_cart_user_fstore.php", data: up, cache: false, success: function(r){ var obj = jQuery.parseJSON(r); $('#item').html(obj.code); }, }); and in PHP I'm echoing the JSON array
$hello = "I am code!"; $response = array(); $response['code'] = $hello; echo json_encode($response); Now I know that in case of echoing more than 1 variable JSON is appropriate...But is it necessary here? And am I using JSON properly..?
Please explain..