Problems with Webview and httpClient in titanium

I am trying to create a simple application using the studio Titanium, which will download google.com, but I do not get the proper results.

1) I used WebView to load the url but nothing was displayed except a white screen.

2) I used httpClient, but always got the error that I defined in the onerror function.

Both methods are inserted below. Should I make changes to the resolution of tiApp.xml ie?

Please help me, how can I do it better?

Note. I am using proxy internet. The problem occurs both on the emulator and on the device.

I am downloading the following js file from app.js

var win = Ti.UI.currentWindow; Ti.App.fireEvent('show_indicator'); //display loading spinner until webview gets loaded var fbUrl = "http://www.facebook.com"; var extwebview = Titanium.UI.createWebView({ url:fbUrl, backgroundColor:'#ccc' }); win.add(extwebview); //adding webview in current window extwebview.addEventListener('load', function() { Ti.App.fireEvent('hide_indicator'); //Hide the Loading indicatr }); 

--------------- Method 2 -----------------

 var url ="http://www.google.com.pk"; var xhr = Ti.Network.createHTTPClient({ onload: function() { // I don't know what to write here. }, onerror: function(e) { Ti.API.debug("STATUS: " + this.status); Ti.API.debug("TEXT: " + this.responseText); Ti.API.debug("ERROR: " + e.error); alert('There was an error retrieving the remote data. Try again.'); }, timeout:50000 }); xhr.open("GET", url); xhr.send(); 
+4
source share
3 answers

Your code for method 1 looks good. Is a loading event happening? I would recommend that you add an "error" event handler to the WebView and see if it gets fired?

 extwebview.addEventListener('error', function(e) { Ti.API.debug("Oh no!"); }); 

The error event does not fire for 404 or other HTTP related errors. Another test option would be to set the html value for your web browser instead of loading an external URL and make sure that everything else works correctly with your WebView and that you can see the html. You may have problems with your proxy.

 var extwebview = Titanium.UI.createWebView({ html:"<html><head></head><body><h1>YOU MADE IT!</h1></body></html>", backgroundColor:'#ccc' }); 
+1
source

Your first code works fine, and I can't help but think that your problem is with your win variable.

  • Perhaps your window does not open? those. try win.open () at the end of your code.

  • Could you check if the winnings in the object window are correctly filled, Ti.UI.currentWindow can be used only in certain cases when the window is created from a URL.

If they still do not work, can you specify the code from the app.js file?

0
source

Your url problem ... I went crazy with this once lol

http://www.google.com.pk

it should be

http://www.google.com.pk

essentially, if you have a webview called detailwebview in your view, you can do

$. detailwebview.url = "http://www.google.com.pk"

Hooray!

0
source

Source: https://habr.com/ru/post/1447739/


All Articles