Home >Backend Development >PHP Tutorial >$.post submits data and returns data method instance in json format

$.post submits data and returns data method instance in json format

小云云
小云云Original
2018-03-05 11:23:505797browse

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=&#39;type&#39;  select" onchange="getType(&#39;Deal/gettype&#39;, 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn