jquery - How to get php array as a javascript array through ajax -


i have php file called ajax, printed array, , want array in ajax success event , use javascript array prepend valu in 2 fields jquery. tried bellow failed. new in coding, pls me one....

the php file bellow:

$qry = $crud->select("latest_event", "bndescription, eventheading","eventid='{$eventid}'");

$data = mysql_fetch_assoc($qry);

$arr = array("content" =>$data['bndescription'], "heading" => $data['eventheading']);

header('content-type: application/x-json');

echo json_encode($arr);

?>

the javascript is:

$.ajax({       type: "post",       url: "geteventdata.php",       data:"eventid="+eventid+"&lang="+lang,       cache: false,       success: function(data){       $("input#eventheading").prepend(data[heading]);       $("textarea#cont").prepend(data[content]);       } 

});

data[heading] 

you don't have heading variable.

to property name, write

data.heading 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -