本文主要和大家分享以$.post方式提交数据 并以json格式返回数据的方法实例,希望能帮助到大家。
js部分
<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部分
public function gettype(){
$where['id'] = trim($_post['id']); $info = m('formula')->where($where)->find(); echo json_encode($info);exit;
}
html部分
<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>
相关推荐:
jquery中$.post()方法的简单实例
jquery如何实现ajax技术2:$.post()
javascript将url解析为json格式的两种方法
以上就是$.post提交数据并以json格式返回数据方法实例的详细内容。