Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a php file called by ajax, where I printed an array, and I want to get the array in the ajax success event and use as javascript array to prepend as valu in two fields with jquery. I tried it as bellow but failed. actually I am new in coding, Pls help me any one....

the php file is as 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]);
      }

});

share|improve this question

2 Answers 2

up vote 1 down vote accepted
data[heading]

You don't have a heading variable.

To get the property with that name, simply write

data.heading
share|improve this answer

From what I can see in your code, you are returning valid json from your php, but it seems that you have not told $.ajax() what kind of data is being returned. You need to set dataType: 'json' in your $.ajax() call.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.