企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
#### html页面需要加入 ~~~ <meta http-equiv="Access-Control-Allow-Origin" content="" /> <meta http-equiv="content-security-policy" /> ~~~ #### php端需要加 ~~~ header('Access-Control-Allow-Origin:*'); ~~~ #### jsonp ajax可以这样写 ~~~ var href='http://qxu1142200245.my3w.com/index.php/Home/Login/login'; jQuery.ajax({ url:href, data:{ username:account, password:password }, dataType: "jsonp", success: function(json){ if(json.status==1){ mui.toast(json.info); localStorage.setItem('username',account); mui.openWindow({ id:'home', url:'home.html', show:{ aniShow:'pop-in' }, waiting:{ autoShow:true } }); }else{ mui.toast(json.info); } }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } }) ~~~ #### thinkphp 后端可以这样哦 ~~~ public function login(){ //if(!IS_AJAX) $this->error('页面不存在'); $username=I('get.username'); $password=md5(I('get.password')); $userDb=M('user')->where(array('username'=>$username))->find(); if($userDb['password']!=$password){ $data=array( 'info'=>'用户名或密码不正确', 'status'=>0, ); $this->ajaxReturn($data,'jsonp'); }else{ $data=array( 'info'=>'登录成功!正在跳转', 'status'=>1, ); $this->ajaxReturn($data,'jsonp'); } } ~~~