Reputation: 63
i have this json data being sent from my php:
echo json_encode(
array(
"Doctitle" => htmlentities($Doctitle),
//"doctype" => htmlentities($doctype),
)
);
I hm trying to get the value displayed in jquery like so :
$.post($("#add_title").attr("action"), $("#add_title").serialize(),
function(data) {
var fileI= data;
var fileInput2= fileI[0].Doctitle;
.......});
But all i get is undefined.and when i only check the fileI variable, there is a string:
{"Doctitle":"sssvvv"}
how can I get the value sssvvv from this??
Upvotes: 0
Views: 18
Reputation: 7680
jQuery is supposed to be able to guess the content type; but for best practice, your PHP script should clearly indicate the content type (do this before any output):
header('Content-type: application/json');
You can then access your data in javascript:
$.post($("#add_title").attr("action"), $("#add_title").serialize(),
function(data) {
var Doctitle = data.Doctitle;
}
);
Upvotes: 1