Reputation: 520
I am trying to build simple app using Titanium studio which will load google.com but I am not getting proper results.
1) I used WebView to load url but nothing display except white screen.
2) I used httpClient but i always got error which i defined in onerror function.
Both methods are pasted below. Do i have to make changes in tiApp.xml i.e interent permission?
Kindly help me, how can i do this better?
Note: I am using proxy internet. Problem comes on both emulator and device.
I am loading 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();
Upvotes: 4
Views: 1557
Reputation: 11
Your problem is with the url...I went crazy with this once lol
should be
http://www.google.com.pk
essentially if you have a webview called detailwebview in your view then you can do
$.detailwebview.url = "http://www.google.com.pk"
cheers!
Upvotes: 0
Reputation: 627
Your first code works fine and I can't help but think that your problem is with your win variable.
Is your window possibly not opened? i.e. try win.open() at the end of your code.
Could you test if win is correctly populated with the window object, Ti.UI.currentWindow can only be used in certain instances when the window is instantiated from a url.
If these still do not work could you supply the code from your app.js file?
Upvotes: 0
Reputation: 55
Your code for Method 1 looks good. Does your load event ever fire? I would recommend you add a handler for the "error" event on the WebView and see if that is being fired?
extwebview.addEventListener('error', function(e) {
Ti.API.debug("Oh no!");
});
The "error" event will not fire for 404 or other HTTP related errors however. Another option for testing would be set the html value for your webview instead of loading an external URL and make sure everything else with your WebView is working correctly and that you can see html there. You may be having trouble with your proxy.
var extwebview = Titanium.UI.createWebView({
html:"<html><head></head><body><h1>YOU MADE IT!</h1></body></html>",
backgroundColor:'#ccc'
});
Upvotes: 1