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

小云云
Release: 2023-03-20 18:36:02
Original
5756 people have browsed it

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>
Copy after login

PHP part

    public function gettype(){
        $where['id'] = trim($_POST['id']);        $info = M('formula')->where($where)->find();        echo json_encode($info);exit;
    }
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template