您可以使用
droidQuery,它是jQuery的Android端口,并包含jQuery的大部分功能和语法,包括Ajax.例如:
$.ajax(new AjaxOptions().url("http://www.example.com").type("GET").dataType("json").success(new Function() {
@Override
public void invoke($d, Object... args) {
JSONObject json = (JSONObject) args[0];
//TODO handle json. If expecting a JSONArray, just cast args[0] to JSONArray.
}
}).error(new Function() {
@Override
public void invoke($d, Object... args) {
AjaxError error = (AjaxError) args[0];
Toast.makeText(MyActivity.this, "Error (" + error.status + "): " + error.reason, Toast.LENGTH_LONG).show();
}
}));