简体   繁体   English

如何在Phonegap上从服务器访问资产资源

[英]How to Access asset resources from server on phonegap

I am on developing cross platform phonegap application.Here i am loading a webpage which is hosted in server. 我正在开发跨平台的phonegap应用程序。这里我正在加载托管在服务器中的网页。 i have done it by changing my loadUrl(" . . .*/server/index.html"); 我必须改变我的使用loadURL做了( “* /服务器/ index.html的。”);

Then I want to know is there any way to load required css/image files from assets folder on phonegap.Like what we are doing when all files are reside in www folder of phonegap. 然后我想知道有什么方法可以从phonegap上的assets文件夹加载所需的css / image文件,就像当所有文件都位于phonegap的www文件夹中时我们正在做什么。

I have tried this but it got error, local resource cannot be accessible. 我已经尝试过了,但是出现错误,无法访问本地资源。 And I am asking is there any possible way to do so??? 我问有没有办法做到这一点???

I am once more mentioning that i am trying for a cross platform application. 我再一次提到我正在尝试跨平台应用程序。

Thanks in advance for your valuable reply... 预先感谢您的宝贵答复...

So what I understand from your question is: 因此,我从您的问题中了解到的是:

  1. you access a html page from server 您从服务器访问html页面

  2. you want that page to use local resources such as image. 您希望该页面使用本地资源,例如图像。

So answer to this question is simply No , you cant do it . 因此,对这个问题的答案就是 ,你做不到


but yes, you can change your approach a little bit, and still download html from server and use local images from assets. 但是可以,您可以稍作更改,仍然可以从服务器下载html并使用资产中的本地图像。

let the page be on the app itself, and just load the html from the server using ajax . 让页面位于应用程序本身上,然后使用ajax从服务器加载html。

Steps: 脚步:

1) index.html will reside within the app 1)index.html将驻留在应用程序内

2) download html from server using ajax call ex: 2)使用ajax调用ex从服务器下载html:

 $(function () { $.ajax({ url: "yourserver.com/getHtml", dataType: "html", // set the datatype to html success: function (data) { // append the data here to page } }); }); 

Now, that you have loaded the html for the page from server, still your page is local So you are now able to load local assets like images into your webpage like you normally do from www folder. 现在, 您已经从服务器加载了该页面的html,但您的页面仍然是本地的,因此您现在可以像通常从www文件夹中那样将本地资源(如图像)加载到您的网页中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM