当地Ajax请求/煎茶/ PhoneGap的Andr​​oid上 [英] Local Ajax request / Sencha / PhoneGap on Android

查看:179
本文介绍了当地Ajax请求/煎茶/ PhoneGap的Andr​​oid上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过本地Ajax请求加载在PhoneGap的应用一些内容。这似乎是工作在iPhone上罚款,而Android不会找到该文件。

I am trying to load some content in a PhoneGap App via a local Ajax request. It seems to work fine on iPhone, but Android wont find the file.

它是这样的:

Ext.Ajax.request({
        url: 'file:///android_asset/webapp/content/file.html',
        success: function(response, opts) {
            console.log('response ' + response.responseText);
        }
        failure: function(response, opts) {
            console.log('response ' + response.responseText);
        }
    });

我已经调整了清单并没有设置Internet权限,仍然没有成功。

I already adjusted the Manifest and did set the Internet Permission, still no success.

你有什么想法?

推荐答案

我在做的情况下,这样是为了摆脱对像煎茶或jQuery的第三方库的依赖,并直接进入使用XHR的第一件事。还有就是从文件协议提出请求有时会返回0状态时,它实际上是200大多数图书馆有这个固定的,但你永远不知道的问题。试试这个XHR code这应该只是伟大的Andr​​oid上:

The first thing I do in situations like this is to get rid of the dependency on third party libraries like Sencha or jQuery and go straight to use XHR. There is an issue where making requests from file protocol sometimes returns a status of 0 when it actually is 200. Most libraries have this fixed but you never know. Try this XHR code which should work just great on Android:

var request = new XMLHttpRequest();
    request.open("GET", "file:///android_asset/webapp/content/file.html", true);
    request.onreadystatechange = function(){
        if (request.readyState == 4) {
            if (request.status == 200 || request.status == 0) {
                console.log("response " + request.responseText);
            }
        }
    }
    request.send();

这篇关于当地Ajax请求/煎茶/ PhoneGap的Andr​​oid上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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