dongwh1992 2014-09-18 18:46
浏览 52

排球响应字符串不起作用

I tried to get response but response are shown in public void onResponse(String response) response variable.When i parse variable from jsonobject .its not show anything.

private void requestData(String uri) {

    user = username.getText().toString();
     pass = password.getText().toString();

     RequestQueue queue = Volley.newRequestQueue(this);

    StringRequest myReq = new StringRequest(Request.Method.POST,uri,
            new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {
                    pb.setVisibility(View.INVISIBLE);

                    try {

                        JSONObject obj = new JSONObject(response);
                        JSONObject data = obj.getJSONObject("status");

                        Toast.makeText(MainActivity.this, data.toString(), Toast.LENGTH_LONG).show();

                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }               

                }
            },
            new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError ex) {
                    pb.setVisibility(View.INVISIBLE);
                    Toast.makeText(MainActivity.this, ex.toString()+"error", Toast.LENGTH_LONG).show();
                }

            }){
                @Override
                protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();
                params.put("User_Name", user);  
                params.put("Password", pass);

                return params;
        }
    };

        queue.add(myReq);       
}

In the Web browser php json response are show:

����������{"status":true,"message":"user are login."}

php code is:

function logedin_post(){

    $username = $this->input->post('User_Name');
    $password = $this->input->post('Password');
    $check_username = $this->validate_username($username);
    if($check_username==TRUE){
        $check_password = $this->validate_password($password,$username);
        if($check_password==TRUE){              
            $row = $this->common_model->getRecord('*','users','User_Name',$username)->result_array();               
            $sess_array = array(
                'User_ID'=>$row[0]['User_ID'],
                'User_Name'=>$row[0]['User_Name'],
                'User_Role'=>$row[0]['User_Role'],

            );      
            $this->session->set_userdata('admin_logged_in', $sess_array);
            $this->response(array(
                'status'=>true,
                'message'=>'user are login.'
                ));
        }else{

                            $this->response(array(
                'status'=>false,
                'message'=>'Please enter your correct Password.'
                ));
        }
    }else{

                    $this->response(array(
                'status'=>false,
                'message'=>'Please enter your correct Username.'
                ));
    }
}
  • 写回答

2条回答 默认 最新

  • doutu9810 2014-09-18 18:54
    关注

    Check if the POST Params are being sended in the request, if u are not getting any response, it could be that the PHP file is getting an error and u have error_reporting(0) and its showing a blank page, try error_reporting(E_ALL) into the php file.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集