php: public function actionUsername() { $user_data = getrow('users',' mobile_phone='.$_POST['user_mobile']); if ($user_data) { exit(json_encode($user_data)); } } html:function usermobile() { $name = document.getElementById("user_mobile").value; $.ajax({ url:'user/index/username', type:'post', //数据发送方式 dataType:'json', //接受数据格式 (这里有很多,常用的有html,xml,js,json) data: "user_mobile="+ $name, //要传递的数据 error: function(){ //失败 $('#user_name').val('没有该用户!'); }, success: function(msg){ //成功 if(msg){ $('#user_name').val(msg['nick_name']); } } }); }
ajax
最新推荐文章于 2022-06-19 13:50:53 发布