|
- html:
- <script src="/public/js/jquery.js" type="text/javascript"></script>
- <script>
- $.getJSON("http://192.168.1.102/index.php?app=home&mod=Public&act=ajax_check_login&username=%E7%AE%A1%E7%90%86%E5%91%98&password=87127547&jsoncallback=?", function(json){});
- function callback(json){
- alert(json.result);
- }
- </script>
-
- php:
-
- //AJAX验证登陆
- public function ajax_check_login() {
-
- // 数据检查
- if ( empty($_REQUEST['password']) ) {
- echo '0';
- exit;
- }
- $is_logged = false;
- if (isset($_REQUEST['email'])) {
- $is_logged = service('Passport')->loginAdmin($_REQUEST['email'], $_REQUEST['password']);
- }else if ( isset($_REQUEST['username'])) {
- $is_logged = service('Passport')->loginAdmin(urldecode($_REQUEST['username']), $_REQUEST['password']);
- }else if ( isset($_REQUEST['mobile'])) {
- $is_logged = service('Passport')->loginAdmin($_REQUEST['mobile'], $_REQUEST['password']);
- }
-
- $ret = ($is_logged == false?0:1);
- $arr = array('result'=>$ret);
-
- $callback= isset($_GET['callback'])?isset($_GET['callback']):'callback';
- $json = json_encode($arr);
- echo $callback.'('.$json.')';
- }
复制代码
|
|