在Android的Java的阿贾克斯后的数据 [英] Ajax post data in android java

查看:1017
本文介绍了在Android的Java的阿贾克斯后的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的T阿贾克斯,但相当熟悉的Andr​​oid。我是一个AJAX程序转换到Android应用程序。作为它的一部分,我需要将数据发布到服务器。下面是阿贾克斯给定post命令。

I am new t ajax, but quite familiar with android. I am converting a ajax program to android app. As a part of it, i need to post data to the server. Below is the given post command in ajax.

var postTo = 'xyz.php';
 $.post(postTo,{employee_name: $('[name=employee_name]').val() , phone: $('[name=phone]').val(), employee_type: 'guest' } ,
 function(data) {

 if(data.success){
 window.localStorage["sa_id"] = data.mid;
 window.location="getempdb.html";
 }

 if(data.message) {
 $('#output').html(data.message);
 } else {
 $('#output').html('Could not connect');
 }
 },'json');

我想在安卓但根据从上述表述很少实现这一点。谁能谁善于阿贾克斯帮我出这个事情。截至目前,我得到的用户名和电话号码作为一个编辑文本输入。我需要发送这一点使用HTTP客户端到PHP。我知道如何使用PHP来传送数据,但不知道送什么格式和字符串是否其发送或作为JSON对象发送。请际$ P $帮助pting上述code和效劳。

I want to implement this in android but under very little from the above statements. Could anyone who is good at ajax help me out with this thing. As of now, i get the user name and telephone number as a edit text input. I need to send this to php using http client. I know how to send data using php, but do not know what format to send and whether its a string to send or as a json object to send. Please help in interpreting the above code and oblige.

推荐答案

显然,这使用 UrlEn codedFormEntity 如果您正在使用的HttpClient android系统中。

Apparently, this uses UrlEncodedFormEntity if you are using HttpClient in android.

这是通过使用列表创建的NameValuePair <​​/ code>。

This is created by using a List of NameValuePair.

从参数到$ .post的:

from the parameters to the $.post:

{employee_name: $('[name=employee_name]').val() , phone: $('[name=phone]').val(), employee_type: 'guest' }

您必须创建一个对的NameValuePair <​​code> employee_name ,一个电话 ...每一个从取一个HTML元素的名称 employee_name 电话 ...这是你把值从EditTexts。

You have to create a NameValuePair for employee_name, one for phone ... each of which is fetched from a HTML element name employee_name, phone ... This is where you put the values from your EditTexts.

它返回一个JSON格式的字符串,你必须解析(通常使用的JSONObject的obj =新的JSONObject(结果); 一旦你从服务器获取的结果)

It returns a JSON formatted String, which you have to parse (typically using JSONObject obj = new JSONObject(result); once you have fetched the result from the server)

在此JSON对象,您有一个名为键成功,其格式不指定,除了你可以假设,一切都很顺利,如果它是present;一键中期,和键的消息

In this JSON object, you have a key named success, which format is not specified, except you can assume things went well if it is present ; a key mid, and a key message.

这篇关于在Android的Java的阿贾克斯后的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆