1

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]);
      }

});

0

2 Answers 2

1
data[heading]

You don't have a heading variable.

To get the property with that name, simply write

data.heading
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.