java中阿贾克斯,在Android的Java的阿贾克斯后的数据

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');

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.

解决方案

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

This is created by using a List of NameValuePair.

from the parameters to the $.post:

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

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.

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)

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.

阿贾克斯(Ajax)是一种实现前后端交互的常用方法。它通过在不刷新整个页面的情况下,使用JavaScript和XMLHttpRequest对象与后端进行通信,实现数据的异步加载和发送。阿贾克斯可以在不断用户操作的情况下,向服务器发送请求并接收响应,从而实现动态更新页面内容的效果。阿贾克斯可以通过JavaScript的原生ajax方法或者jQuery库封装的ajax方法来使用。 在前后端交互的流程阿贾克斯通常有三个主要的步骤:发送请求、接收响应和处理响应数据。通过使用阿贾克斯,前端可以与后端进行数据的异步传输和交互,实现更加灵活和高效的网页应用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ajax后端怎么写?如何实现前后端交互(代码示例)](https://blog.csdn.net/weixin_33728774/article/details/115155386)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [ajax工作原理 前后端交互流程](https://blog.csdn.net/m0_68331234/article/details/124332667)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值