简体   繁体   English

使用volley将数据从android发送到php

[英]Sending data from android to php using volley

The variables am sending to the server side can't seem to get there and i just can't figure out what the problem is. 发送到服务器端的变量似乎无法到达那里,我只是无法弄清楚问题是什么。 I get back a response from the PHP script saying that the POST is empty. 我从PHP脚本返回一个回复,说POST是空的。

How its supposed to work 它应该如何工作

  • insert comment in the alert dialog 在警告对话框中插入注释
  • both the id and comment have to be posted to the server side 必须将id和comment都发布到服务器端

please help!!! 请帮忙!!!

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                /* Alert Dialog Code Start*/
                AlertDialog.Builder alert = new AlertDialog.Builder(context);

                final String id_number =((TextView)view.findViewById(R.id.textViewIdnum)).getText().toString();

                alert.setTitle("Alert id: "+id_number); //Set Alert dialog title here
                alert.setMessage("Enter Your Comment here"); //Message here

                // Set an EditText view to get user input
                final EditText input = new EditText(context);
                alert.setView(input);

                alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // convert the input to a string and show in a toast.
                        String reason = input.getEditableText().toString();
                        Toast.makeText(SearchActivity.this,"Commenting...", Toast.LENGTH_LONG).show();

                        final String reason_key = input.getText().toString().trim();
                        //final String id_number_key = textview;

                        StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.RESULT_URL,

                                new Response.Listener<String>() {
                                    @Override
                                    public void onResponse(String response) {
                                        Toast.makeText(SearchActivity.this,response,Toast.LENGTH_LONG).show();
                                    }
                                },
                                new Response.ErrorListener() {
                                    @Override
                                    public void onErrorResponse(VolleyError error) {
                                        Toast.makeText(SearchActivity.this,error.toString(),Toast.LENGTH_LONG).show();
                                    }
                                });
                        Map<String,String> params = new HashMap<String, String>();
                        params.put(TAG_IDNUM,id_number);
                        params.put(reason_key,reason);

                        RequestQueue requestQueue = Volley.newRequestQueue(SearchActivity.this);
                        requestQueue.add(stringRequest);

                    } // End of onClick(DialogInterface dialog, int whichButton)
                }); //End of alert.setPositiveButton
                alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                        Toast.makeText(SearchActivity.this,"Commenting cancled",Toast.LENGTH_LONG).show();
                        dialog.cancel();
                    }
                }); //End of alert.setNegativeButton
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
   /* Alert Dialog Code End*/
                // End of onClick(View v)


            }




        });}
catch (JSONException e){}
}

1st you need to test if you php code is working, use postman to test your "api" if it works with postman your code should work. 首先,你需要测试你的PHP代码是否正常工作,使用邮递员来测试你的“api”,如果它适用于postman你的代码应该工作。

In my opinion it's more a php fail than an android one. 在我看来,它更像是一个PHP失败而不是一个Android失败。

Does your 请问您

 Toast.makeText(SearchActivity.this,response,Toast.LENGTH_LONG).show();

print something ? 打印什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM