Ajax Submit failing in webview

You must Login before you can answer or comment on any questions.

I am using the webview control to display a form from a live webserver as part of my app. The form works fine in the mobile browsers but fails when displayed through the titanium webview. I am using the following jquery function to submit the contents of the form and display the response in a div

function get2(){
    $('#formresult').html("Submitting... Please wait.");
    $.post("http://www.mywebsite.com/submitform.asp", $("#form").serialize(),
 
       function(output){
            $('#formresult').html(output).show();
        });
    }
Works perfectly in mobile a desktop browsers and even in a phonegap implementation but not in Titanium webview. Do I need do make any special settings since it is cross domain maybe? Any direction here is appreciated.

2 Answers

If the form come local from app then you have no problems because the same domain restriction not active. In your case the url must be the same domain as the form.

— answered 2 years ago by Rainer Schleevoigt
answer permalink
1 Comment
  • If the html form is inside the titanium app and its doing a submit to a webpage on the internet (external domain) is there a way to whitelist that domain so the titanium project will let them communicate. I love titanium and have abandoned PhoneGap in favor of it but PhoneGap seemed to no restrict this kind of cross-domain activity. Thanks for the quick reply!

    — commented 2 years ago by Kevin Thomas

I had a similar issue. Whenever I use ajax to populate a content of a DIV element the whole webview become completely blank (white). It worked for the first ajax call though.

I have to call reload event of the webview from my web page after the ajax is finished and the html is set to the DIV.

This is my code inside the app.js

//this loads my external web app using an iframe.
var webview = Titanium.UI.createWebView({url: 'index.html'}); 
 
//further code truncated
 
Titanium.App.addEventListener('web:reloadWebView', function() {
    webview.reload();
});

From my external web app, I have to call this after the ajax call is loaded in order to make the page displayed properly.

if (typeof TiApp != 'undefined') {
    TiApp.fireEvent('web:reloadWebView', {
    });
}
webview.repaint(); did not help solve my issue I had to use webview.reload();

Please let me know if there is a better solution.

Thanks!

Your Answer

Think you can help? Login to answer this question!