Home >PHP Framework >ThinkPHP >How to call ajax to load data without refreshing in thinkphp5.0

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

藏色散人
藏色散人forward
2020-09-27 14:10:242816browse

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)
})

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();
                }
            }
        })

    });
}
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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete