Titanium API on a remote webview
Hello, I am not sure if this is actually possible, I have been trying with no luck, buy maybe you can help me.
What I am trying to do is run some basic Titanium API calls from a remote web view.
So, for example, I have a data.js which calls a http://example.com/data.php.
Is it possible to fire Titanium API calls from the php file under the <script>
tag?
I tried with no luck, but maybe I am doing something wrong.
I appreciate all the help you can give me.
Thanks!
4 Answers
-
Yak
Allowing remote web pages to run local operating system commands would be a serious security risk.
It's difficult to advise you without knowing in more detail what you wish to achieve. However, you can call a php webpage just like an html page, using Ti.Network.HTTPClient. For example, in it's simplest form, see photo_gallery.js, and note the open/GET statement (the .png extension could be a .php extension).
For a GET request with parameters, see foursquare.js, and take note of the
resp
variable that contains data returned from the server, and thevenues
variable that utilises that data.Hope this is clear.
Good luck
-
No you cannot.
The only way would be to use the httpclient to fetch the content of the remote page and populate the webview using this content with the html property
This way the webview will think the content is local and will let you make the calls. -
Hello! thanks for the answers.
I created an app with the old Titanium API and it was all done with js and HTML. The data was retrieved via XML which I guess is the way to go also with this API, the thing is that I notice that views changed a lot so my old way of calling this url:file.html is not working anymore under the CreateWindow…I guess I will try to learn how to do all that I need directly using API elements and not HTML.
Anyway, thanks a lot for the quick help!
-
Yak
Note that you cannot pass an .html document to the url property of createWindow(). If you want to do this, use a webView instead.
Cheers