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

});

asked Oct 6, 2013 at 23:47
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
answered Oct 6, 2013 at 23:49
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.

answered Oct 6, 2013 at 23:51

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.