javascript - Displaying returned json data from controller with AJAX -
i trying send post submission controller, , want receive json string can append information table. here's have far:
my ajax call:
$('#addticketbutton').click(function(){ $.ajax({ type:'post', url:'<?php echo site_url();?>ticket_system/add_ticket', data:{ 'headline': $("#headline").val(), 'description': $('#description').val(), 'category': $('#category').val(), 'priority': $('#priority').val(), 'assigned': $('#assign').val() }, datatype: 'json', success: function(data){ $("#created_table > tbody:last-child").append("<tr><td>" + data[0].ticketid + "</td><td>" + $("#headline").val() + "</td><td>" + data[0].lastupdated + "</td></tr>"); } }); });
my controller:
public function add_ticket() { $ticket = array( 'headline' => $this->input->post('headline'), 'description' => $this->input->post('description'), 'category' => $this->input->post('category'), 'priority' => $this->input->post('priority'), 'assigned' => $this->input->post('assigned'), 'userid' => $this->userid ); $ticketid = $this->tickets->addticket($ticket); $ticket = $this->tickets->getticketbyticketid($ticketid); $success = array( 'ticketid' => $ticketid, 'lastupdated' => date("m d, y h:i a") ); echo json_encode($success); }
i have tried using:
data.ticketid
but didn't work either.
any me appreciated. thank you!
not sure, can try this:
controller:
$success = json_encode($ticketid||date("m d, y h:i a")); //added '||' between results
ajax :
d = data.split("||"); //break results $("#created_table > tbody:last-child").append("<tr><td>" + d[0] + "</td><td>" + $("#headline").val() + "</td><td>" + d[1] + "</td></tr>");
Comments
Post a Comment