Adsense
Popular Posts
- Install APXS in Redhat Linux
- MySQL workbench -"Could not decrypt password cache"
- Transfer modules between sites
- JavaScript, remove trailing insignificant zeros after toFixed function
- Set Windows path command line
- datatable order by nunmeric
- MySQL date created and date modified
- super(props) in React
- PHP, dump varailbes in a format way
- React: connect(mapStateToProps, mapDispatchToProps)
Thursday, May 12, 2016
jquery - Parse JSON with jQuery Example
jquery - Parse JSON with jQuery Example
$.parseJSON - Takes a well-formed JSON string and returns the resulting JavaScript value.
Example:
$.post("../_ajaxParts/preplanning/preplanning.php", {
funct: 'getPrePlanning',
stakeholder_id:stakeholder_id,
pad_id:pad_id,
site:site,
}, function(data) {
formattedJson= $.parseJSON(data);
formatPrePlanningBox(formattedJson)
});
In preplanning.php, we use json_encode to convert to json format.
<?php
if($_POST['funct'] == "getPrePlanning") {
$preplanning = new preplanning();
$model = new PreplanningSummaryModel();
$pad_id =$_POST['pad_id'];
$total_semester= $model->get_total_semester($pad_id);
$coursepre_choice= $model->get_coursepre_choice($pad_id);
$data = $preplanning->getPrePlanning($_POST);
$CoursePre = $preplanning->getCoursePre($_POST);
$arrayForJSON = array("count" => count($data), "coursepre_choice" => $coursepre_choice, "total_semester" => $total_semester, "data" => $data, "CoursePre" => $CoursePre);
echo json_encode($arrayForJSON);
}
?>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment