Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

mobileweb 3.0 and XHR requests and CORS

$
0
0

Really hoping somebody can help me here. I'm trying to use TI to test and debug a simple mobileweb app (3.1.1) that uses an XHR request. I'm on OSX. Same code works fine in android/ios emulators. As far as I know I'm doing everything correctly.

  • I've read the docs on XHR and understand this is a cross-origin request. I know I could use Ti.Network.httpURLFormatter and a proxy but could not find any documentation or examples anywhere on this site (I'd be grateful if you know of any). So I went down the route of enabling CORS.
  • I've tried it using a known-cors-enabled test site https://cors-test.appspot.com/test - and was able to get a valid response - so the code seems correct
  • I've enabled CORS on my server (IIS 6) and the sites
  • I've used Fiddler2 to track the same request in a browser and have confirmed it's sending the Access-Control-Allow-Origin: * header back, so the correct header appears to be in place

But trying to run my request out of TI, returns the same error code 0 and text "Can't reach host"

Any suggestions? Is there anything else I need to do on the TI side? Anything I need to enable for testing? Anything else I need to add to the server side? I've searched the forums here and am just stuck. There doesn't seem to be a lot of documentation about this, but I don't know how you could ever test an app that retrieves data via XHR without enabling cors so it must be something simple.

Have paired it down to a simple example

var xhr = Titanium.Network.createHTTPClient();
 
    xhr.onload = function() {
        alert(xhr.status + '- ' + xhr.statusText + ' responsedata' + xhr.responseData + '  text:'   +   xhr.responseText )
    };
 
    xhr.onerror = function(e) {
        alert('error:' + e.error);
    };
     //correct request
     var t_ReqUrl = 'https://<<myrequest>>';  
 
     // known test site - uncomment this and I get a valid response
    //  t_ReqUrl = 'https://cors-test.appspot.com/test';
 
    xhr.open('GET',t_ReqUrl);
 
    // send 
    xhr.send();
Any ideas? Really appreciate it.

Viewing all articles
Browse latest Browse all 8068


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>