可Ajax调用Android中做什么?中做、Ajax、Android

2023-09-10 17:38:44 作者:少年你可曾听说.

我正在开发中,我有搜索选项的应用程序。在该搜索框,如果我输入'一'我想我所有的朋友开始用所有的名字,我会得到Web服务器。但是,我已经同时使请求,输入每个字母。但是,当我用Google搜索,我得到了不同的反应。有人说Ajax调用是不可能的Andr​​oid系统。 Android的基本上是基于java。那么,为什么不能进行Ajax调用。任何人都可以指导我在Android的有关AJAX调用一个很好的链接是否有可能?

I'm developing an application in which I've got search option. In that search box, if I type 'a' I want all names of all my friends starting with a, which I'll get from web server. But for that I've to make request simultaneously with typing each letter. But when I googled, I got mixed reactions. Some people said Ajax call is not possible in Android. Basically Android is based on java. Then why is not possible to perform AJAX calls. Could anyone guide me to a good link related to AJAX call in Android if it is possible ?

推荐答案

您可以使用 droidQuery ,这是< STRONG>的jQuery 的Andr​​oid的端口,包括了大部分的功能​​和语法的的jQuery 的,其中的阿贾克斯的。例如:

You can use droidQuery, which is The Android port of jQuery, and includes most of the features and syntax of jQuery, including Ajax. For example:

$.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();
    }
}));