Aquery ajax请求似乎没有在android中启动

时间:2016-01-06 14:44:18

标签: android jquery json ajax aquery

我认为我为从json中的服务器获取数据而构建的代码没有启动。在logcat中,没有来自" log.v"的文本。此外,我所做的代码似乎并不一直是try catch。我使用Aquery来获取ajax请求。

有没有其他问题吗?

我想将json放入一个hashmap,这样我就可以构建一个listview,但是我无法将json中的数据导入logcat

Greathings

public class film_sound extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Get the view from fragmenttab1.xml
        View view = inflater.inflate(R.layout.activity_film_sound, container, false);
        Context context = inflater.getContext();
        String[] Film_Data =  getArguments().getStringArray("Film_Data");

        File ext = Environment.getExternalStorageDirectory();
        File cacheDir = new File(ext, "/android/data/be.moviechecker.programma/case");
        AQUtility.setCacheDir(cacheDir);
        final AQuery aq = new AQuery(context);

        /*Ophalen van de json*/
        String url = "http://app.be/data_2_0_0/sound.php?id=1";
        aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {
            @Override
            public void callback(String url, JSONObject json, AjaxStatus status) {
                if (json != null) {
                    JSONArray jArray = null;
                    try {
                        jArray = json.getJSONArray("soundtrack");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    if (jArray.length() == 0) {
                        Log.v("debug", "dataleeg");
                    } else {
                        for (int i = 0; i < jArray.length(); i++) {
                            JSONObject json_data = null;
                            try {
                                json_data = jArray.getJSONObject(i);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            try {
                                Log.v("debug", json_data.getString("naam"));
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                } else {
                    //ajax error, show error code
                    Log.v("debug", aq.getContext() + "Error:" + status.getCode());
                }
            }
        });

        return view;
    }
}

1 个答案:

答案 0 :(得分:0)

在手机屏幕中,您必须在 config.xml

启用跨域请求
<access origin="http://domain.com/public/auth/app-login"/>

也许你可以看看这个:
WebView Javascript cross domain from a local HTML file