Home > PHP Framework > ThinkPHP > body text

Usage example of ajaxReturn in thinkphp

藏色散人
Release: 2020-12-31 09:04:49
forward
8136 people have browsed it

The following is the thinkphp framework tutorial column to introduce the usage of ajaxReturn in thinkphp. I hope it will be helpful to friends in need!

Usage example of ajaxReturn in thinkphp

1. Example:

if ($codeid = $model->addCustomer($this->admin["id"])) {
            $data["code"] = 10000;
            $data["message"] = "添加客户成功。客户编号为:{$codeid}";
            $data["data"] = 0;

            $this->ajaxReturn($data);
        } else {
            $data["code"] = 10001;
            $data["message"] = $model->failAddCustomer();
            $data["data"] = 0;

            $this->ajaxReturn($data);
        }
Copy after login

2. Return data:

$data

3.Receive data.

For example:

$.ajax({
                    type : "POST",
                    url : "<?php echo U(&#39;policy/addCustomer&#39;); ?>",
                    dataType : "JSON",
                    data : data,
                    success : function(eve)
                    {
                        alert(eve.message);

                        if (eve.code == 10000)
                        {
                            window.location.reload();
                        }

                    }
                });
Copy after login

The above is the detailed content of Usage example of ajaxReturn in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!