Titanium Community Questions & Answer Archive

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

XHR in a local WebView: problem on iPhone, works in Simulator

I want to load some data via an AJAX GET from a local HTML file.
I can see the request being processed, the response ist sent to the client, but the success callback is never fired – on the iPhone that is.

I am creating a html file in the applicationDataDirectory, which should be treated as a local file, actually, to prevent any cross-domain issues.

Anyway, the following code works perfectly in Simulator, on the device the request is sent and a response is received, but the callback is never processed.

(the code has been reindented for legibility, the testhtml string is all in one line)

var contentArea = Ti.UI.createWebView({});

var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'index.html');

var testhtml = "<html>
  <script src='app://Resources/html/js/jquery-1.4.2.min.js' type='text/javascript'></script>
  <script type='text/javascript'>
    function test() { 
      $.ajax({url: 'http://www.google.com', 
          success: function() { alert('data received'); }});   
<body onload='test();'></body></html>";


contentArea.url = f.nativePath;

Has anybody got any ideas?

— asked April 10th 2010 by Alexei Matveev
  • ajax
  • mobile
  • webview

0 Answers

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.