Local reference jquery script in nanohttpd (Android)
Ad
I'm working around a web service using nanohttpd. I've following files in assets folder (Android Studio):
All works properly including the direct reference to JQuery:
<script src="http://code.jquery.com/jquery-latest.min.js "></script>
But actually, I will not have Internet connection when I will use the server, so I need the local reference to assets folder.
I tried the simple way but doesn't work:
<script src="jquery_1.11.3.min.js"></script>
I've seen other similiar question (Link) but I can't understand the answer :(.
Can you help me with Jquery Script reference?
Thank you and sorry for my english.
Ad
Answer
Ad
You should use getResources().getAssets() code to access file from assets folder. For example:
private Response getFromAssets(String filename) {
InputStream fis;
try {
fis = this.getResources().getAssets().open(filename);
} catch (IOException e) {
return new Response(Response.Status.OK, "text/plain", "Internal Error: " + e.getMessage());
}
return new Response(Response.Status.OK, /*MIME-type*/ "application/javascript", fis);
}
Ad
source: stackoverflow.com
Related Questions
Ad
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad