Home >Backend Development >PHP Tutorial >$.post submits data and returns data method instance in json format
This article mainly shares with you the method examples of submitting data in $.post method and returning data in json format. I hope it can help you.
js part
<script>function getType(url, id) { $.post(url, {'id': id}, function(res) { $("input[name='formula']").val(res.finally); $("input[name='formula2']").val(res.proportion); }, 'json'); }</script>
PHP part
public function gettype(){ $where['id'] = trim($_POST['id']); $info = M('formula')->where($where)->find(); echo json_encode($info);exit; }
html part
<input name="formula" class="form-control" type="text"><input name="formula" class="form-control" type="text"><select name='type' select" onchange="getType('Deal/gettype', this.value);"> <option value="海口">海口</option> <option value="海口">海口</option> <option value="海口">海口</option></select>
Related recommendations:
A simple example of the $.post() method in jquery
How jquery implements ajax technology 2: $.post()
javascript will Two ways to parse url into json format
The above is the detailed content of $.post submits data and returns data method instance in json format. For more information, please follow other related articles on the PHP Chinese website!