标签:php5 label list clist test div mp3 isa obj
$.get()方法即可
22 <script> 23 $(‘#my_ajax_test‘).click(function(){ 24 var name=$(‘input‘).val(); 25 //alert(name); 26 $.get("{:url(‘test_ajax/index‘)}",{name:name},function(data){ 27 alert(‘Ajax从服务器端返回来的值是:‘+data); 28 }); 29 }); 30 </script>
request()->isAjax(),thinkphp5提供了ajax判断函数isAjax()
8 public function index() 9 { 10 if(request()->isAjax()){ 11 $name=input(‘name‘); 12 return $name.‘ fry‘; 13 //dump($name);die; 14 } 15 return view(); 16 }
举个栗子~:
前台代码:
<script> var spirit = ""; $.get("{:url(‘Music/mclist‘)}",function(data){ console.log(data); var length = Object.keys(data).length; var brr = []; for(var i =0;i<length;i++){ brr.push({ title:data[i]["mc_name"], artist:data[i]["mc_singer"], mp3:data[i]["mc_url"], poster:"" }); } spirit = brr; }); </script>
后台代码:
public function mclist() { if (request()->isAjax()) { // $name = input(‘name‘); // return $name . ‘ fry‘; // //dump($name);die; $mclist = Db::table("music")->select(); return $mclist; } return view(); }
标签:php5 label list clist test div mp3 isa obj
原文地址:https://www.cnblogs.com/weixiaofantasy/p/9945666.html