Home > PHP Framework > ThinkPHP > body text

How to call ajax to load data without refreshing in thinkphp5.0

藏色散人
Release: 2020-09-27 14:10:35
forward
2729 people have browsed it

The following tutorial column from thinkphp will introduce how thinkphp5.0 calls ajax to load data without refreshing. I hope it will be helpful to friends in need!

How to call ajax to load data without refreshing in thinkphp5.0

The controller layer is to adjust the data and return it. I won’t go into details here. The ajax part of the view layer page is written as follows

function shanchu(obj)
{
    var code = $(obj).attr("code");

    $.ajax({
        url:"/index400/Test/sc",
        data:{code:code},
        type:"POST",
        dataType:"TEXT",
        success: function(data){
            if(data==0)
            {
                alert("删除失败!");
            }
            else
            {
                $("#aaa").html(data);
                $(".sc").click(function(){
                    shanchu(this)
                });
            }
        }
    })
}

$(".sc").click(function(){
shanchu(this)
})
Copy after login

Or you can write

shanchu()

function shanchu()
{
    $(".sc").click(function(){

        var code = $(this).attr("code");

        $.ajax({
            url:"/index400/Test/sc",
            data:{code:code},
            type:"POST",
            dataType:"TEXT",
            success: function(data){
                if(data==0)
                {
                    alert("删除失败!");
                }
                else
                {
                    $("#aaa").html(data);
                    shanchu();
                }
            }
        })

    });
}
Copy after login
like this

The above is the detailed content of How to call ajax to load data without refreshing in thinkphp5.0. 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