起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1365|回复: 6

[处理中3] 登录页面错误问题

[复制链接]

10

主题

27

帖子

57

积分

初级会员

Rank: 2

积分
57
QQ
发表于 2016-7-11 10:35:42 | 显示全部楼层 |阅读模式
本帖最后由 yuichao 于 2016-7-11 10:38 编辑

这是我借鉴的别人登录界面,自己修改了下,,然后每次登录都显示数据传输失败w文件
  1. define(function(require){
  2.         var $ = require("jquery");
  3.         var justep = require("$UI/system/lib/justep");
  4.         require("$UI/system/lib/cordova/cordova");
  5. //        require("$UI/blshopApp/JS/Chart.js");
  6.         require("cordova!org.apache.cordova.device");
  7.         
  8.         var Model = function(){
  9.                 this.callParent();
  10.         };

  11.         
  12.         Model.prototype.btnCheckUserLogin = function(event){
  13.                 var userData = this.comp("userData");
  14.                 //用户名和密码为空提示
  15.                 if ( $.trim(userData.val("fusername")) === "" || $.trim(userData.val("fpassword")) === "") {
  16.                         this.comp("messageDialog").show({
  17.                                 "title" : "温馨提示",
  18.                                 "message" : "请输入用户名或密码"
  19.                         });
  20.                 }
  21.                 else
  22.                 {
  23.                         var self = this;
  24.                         //ajax校验用户名和密码
  25.                         $.ajax({
  26.                                 "type" : "post",
  27.                                 "async" : false,
  28.                                 "data":{
  29.                                         "fusername":userData.val("fusername"), //POS提交用户名字段
  30.                                         "fuserpass":userData.val("fuserpass")  //POS提交密码字段
  31.                                 },
  32.                                 "dataType" : "json",
  33.                                 "url" : "http://localhost:8080/checkuserLogin.php", //PHP数据库校验用户名和密码是否正常
  34.                                 "success" : function(data) {
  35.                                         if(data['code']==200){          //php返回200,代表后端程序成功返回查询结果
  36.                                                 localStorage.setItem('username',data['data']['fusername']);  //登录成功存储用户名到html localStorage
  37.                                                 localStorage.setItem('shopname',data['data']['shopname']);  //登录成功存储中文名称到html localStorage
  38.                                                 window.location.href="./index.w";   //登录成功,跳转到APP首页
  39.                                                 
  40.                                         }
  41.                                         else if(data['code']==400) //返回400,代表数据库查询不到记录,用户名或密码
  42.                                         {
  43.                                                 self.comp("messageDialog").show({
  44.                                                 "title" : "温馨提示",
  45.                                                 "message" : "输入的用户名或密码不正确"
  46.                                 });
  47.                                         }
  48.                                 },
  49.                                  "error": function(){
  50.                                                 alert("数据传输失败!");
  51.                                         }                                                              
  52.                         });
  53.                 }

  54.         };
  55.         Model.prototype.openPageClick = function(event) {
  56.                 /*
  57.                  * 1、点击组件增加算定义属性:pagename 2、获取自定义属性,打开 对应页面
  58.                  */
  59.                 var pageName = event.currentTarget.getAttribute('pagename');
  60.                 if (pageName)
  61.                         justep.Shell.showPage(require.toUrl(pageName));
  62.         };

  63.         return Model;
  64. });
复制代码

10

主题

27

帖子

57

积分

初级会员

Rank: 2

积分
57
QQ
 楼主| 发表于 2016-7-11 10:36:26 | 显示全部楼层
db.php
  1. <?php
  2. class Db{
  3.         static private $_instance;
  4.         static private $_connectSource;
  5.         private $_dbConfig = array(
  6.                 'host'=>'127.0.0.1:3306',
  7.                 'user'=>'root',
  8.                 'password'=>'x5',
  9.                 'database'=>'zhaowoya'
  10.         );
  11.         
  12.         private function __construct(){
  13.                         
  14.         }
  15.         static public function getInstance()
  16.         {
  17.                 if(!(self::$_instance instanceof self))
  18.                 {
  19.                         self::$_instance = new self();
  20.                 }
  21.                 return self::$_instance;
  22.         }
  23.         
  24.         public function connect()
  25.         {
  26.                 if(!self::$_connectSource)
  27.                 {
  28.                         self::$_connectSource=mysql_connect($this->_dbConfig['host'],$this->_dbConfig['user'],$this->_dbConfig['password']);
  29.                 if(!self::$_connectSource)
  30.                 {
  31.                         throw new Exception('mysql conncet error'.mysql_error());
  32.                         //die('mysql conncet error'.mysql_error());
  33.                 }
  34.                 mysql_select_db($this->_dbConfig['database'],self::$_connectSource);
  35.                 mysql_query("set names UTF8",self::$_connectSource);
  36.                
  37.                 }        
  38.                 return self::$_connectSource;
  39.         }               
  40. }

  41. ?>
复制代码
回复 支持 反对

使用道具 举报

10

主题

27

帖子

57

积分

初级会员

Rank: 2

积分
57
QQ
 楼主| 发表于 2016-7-11 10:37:29 | 显示全部楼层
本帖最后由 yuichao 于 2016-7-11 10:39 编辑
  1. checkuserLogin.php
  2. <?php
  3. header("Content-Type: application/json;charset=utf-8");
  4. header("Access-Control-Allow-Origin:*");
  5. header("Access-Control-Allow-MethodsOST,GET");
  6. require_once("./db.php");
  7. require_once("./Response.php");

  8.          $fusername =Response::_post('fusername');
  9.          $fpassword =Response::_post('fpassword');
  10.          
  11.         
  12.         if(!isset($fusername)||!isset($fpassword))
  13.         {
  14.                 Response::show(400,'输入的数据不正确');
  15.         }
  16.         else
  17.         {
  18.                 $connect = Db::getInstance()->connect();
  19.                 $sql="select fusername,shopname from user where fusername='"+$fusername+"' and fpassword='"+md5($fpassword)+"'";
  20.                 $result = mysql_query($sql,$connect);

  21.                 if(!mysql_num_rows($result))
  22.                 {
  23.                         Response::show(400,'输入的用户名或密码不正确');
  24.                 }
  25.                 else
  26.                 {
  27.                         $results =mysql_fetch_assoc($result);
  28.                         Response::show(200,'success',$results);
  29.                         
  30.                 }
  31.         }
  32.         
  33.         

  34. ?>
复制代码

回复 支持 反对

使用道具 举报

10

主题

27

帖子

57

积分

初级会员

Rank: 2

积分
57
QQ
 楼主| 发表于 2016-7-11 10:41:10 | 显示全部楼层
Response.php
  1. <?php
  2.         class Response{
  3.                 const JSON="json";
  4.                
  5.         /**
  6.         按综合方式输出通信数据
  7.         *@param integer $code 状态码
  8.         *@param string $message 提示信息
  9.         *@param array $data 数据
  10.         *@param string $data 数据类型
  11.         *return string
  12.         */
  13.                 public static function show($code,$message='',$data=array(),$type=self::JSON)
  14.                 {
  15.                         if(!is_numeric($code))
  16.                         {
  17.                                 return"";
  18.                         }
  19.                         $type=isset($_GET['dataType'])?$_GET['dataType']:'json';
  20.                                 $result=array(
  21.                                 'code'=>$code,
  22.                                 'message'=>$message,
  23.                                 'data'=>$data,
  24.                         );
  25.                         
  26.                         if($type=='json')
  27.                         {
  28.                                 self::json($code,$message,$data);
  29.                                 exit;
  30.                         }elseif($type=='array')
  31.                         {
  32.                                 var_dump($result);
  33.                         }elseif($type=='xml')
  34.                         {
  35.                                 self::xmlEncode($code,$message,$data);
  36.                                 exit;
  37.                         }else
  38.                         {
  39.                                 //TODO        
  40.                         }
  41.                 }        
  42.         
  43.         /**
  44.         按json方式输出通信数据
  45.         *@param integer $code 状态码
  46.         *@param string $message 提示信息
  47.         *@param array $data 数据
  48.         *return string
  49.         */
  50.         public static function json($code,$message='',$data=array()){
  51.                 if(!is_numeric($code))
  52.                 {
  53.                         return '';
  54.                 }
  55.                 $result=array(
  56.                         'code'=>$code,
  57.                         'message'=>$message,
  58.                         'data'=>$data
  59.                
  60.                 );
  61.                 echo json_encode($result);
  62.                 exit;
  63.         }
  64.         /**
  65.         按xml方式输出通信数据
  66.         *@param integer $code 状态码
  67.         *@param string $message 提示信息
  68.         *@param array $data 数据
  69.         *return string
  70.         */        
  71.         public static function xmlEncode($code,$message='',$data=array()){
  72.                 if(!is_numeric($code))
  73.                 {
  74.                         return'';
  75.                 }
  76.                 $result=array(
  77.                         'code'=>$code,
  78.                         'message'=>$message,
  79.                         'data'=>$data,
  80.                 );
  81.                
  82.                 header("Content-Type:text/xml");
  83.                 $xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
  84.                 $xml.="<root>\n";        
  85.                 $xml.=self::xmlToEncode($result);        
  86.                 $xml.="</root>";
  87.                
  88.                 echo $xml;
  89.         }
  90.         
  91.         public static function xmlToEncode($data)
  92.         {
  93.                 $xml=$attr="";
  94.                 foreach($data as $key => $value)
  95.                 {
  96.                         if(is_numeric($key)){
  97.                                 $attr=" id='{$key}'";
  98.                                 $key="item";        
  99.                         }
  100.                         $xml.="<{$key}{$attr}>\n";
  101.                         $xml.=is_array($value)?self::xmlToEncode($value):$value;
  102.                         $xml.="</{$key}>";
  103.                 }
  104.                 return $xml;
  105.         }
  106.         
  107.         public static function _get($str)
  108.         {
  109.                 $val = !empty($_GET[$str]) ? $_GET[$str] : null;
  110.                 return $val;
  111.         }
  112.         
  113.                 public static function _post($str)
  114.         {
  115.                 $val = !empty($_POST[$str]) ? $_POST[$str] : null;
  116.                 return $val;
  117.         }
  118. }

  119. ?>
复制代码
回复 支持 反对

使用道具 举报

发表于 2016-7-11 16:42:02 | 显示全部楼层

报错信息发来看看!
你的php代码可以调试吗??最好是调试看看执行哪行代码出错的?
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

13

主题

24

帖子

67

积分

初级会员

Rank: 2

积分
67
QQ
发表于 2016-7-12 12:08:26 | 显示全部楼层
lz,能把你的登录界面源码分享一下吗
回复 支持 反对

使用道具 举报

10

主题

27

帖子

57

积分

初级会员

Rank: 2

积分
57
QQ
 楼主| 发表于 2016-7-12 14:58:24 | 显示全部楼层
liangyongfei 发表于 2016-7-11 16:42
报错信息发来看看!
你的php代码可以调试吗??最好是调试看看执行哪行代码出错的? ...

The requested resource is not available.

它提示的是这个
回复 支持 反对

使用道具 举报

发表于 2016-7-12 16:14:03 | 显示全部楼层
yuichao 发表于 2016-7-12 14:58
The requested resource is not available.

它提示的是这个

是前台报的错吗???意思是没有请求到后台的代码??那可能就是部署的问题!
可以参考下:http://docs.wex5.com/wex5-runtime-php/

也可以看看 文档中心其他关于PHP文章的介绍!是环境没准备好的问题吧!
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-12 03:05 , Processed in 0.081822 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表