Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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!

— asked December 4th 2010 by CallMePaul
  • iphone
  • remote
  • tituanium
  • webview
0 Comments

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 the venues variable that utilises that data.

    Hope this is clear.

    Good luck

    — answered December 4th 2010 by Paul Dowsett
    permalink
    0 Comments
  • 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.

    — answered December 4th 2010 by Dan Tamas
    permalink
    0 Comments
  • 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!

    — answered December 4th 2010 by CallMePaul
    permalink
    0 Comments
  • 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

    — answered December 4th 2010 by Paul Dowsett
    permalink
    1 Comment
    • Hello Hal, thanks! but in that case, if I change to a webview of local HTML file, can I include all the same calls to the titanium API I would if I user CreateWindow()?

      — commented December 4th 2010 by CallMePaul
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.