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