Android WebView + AJAX local files

后端 未结 2 1109
灰色年华
灰色年华 2020-12-30 08:15

I have an android webview loading a website that I have locally in my assets. I\'ve not built it myself, and I have very little control over the markup, js etc.

Pro

相关标签:
2条回答
  • 2020-12-30 08:56

    You need to allow crossdomain. In this example, crossdomain is allowed for json values and for scripts.

    $.ajaxPrefilter( "json script", function( options ) {
        options.crossDomain = true;
    });
    
    0 讨论(0)
  • 2020-12-30 09:13

    Thanks for answer @njzk2, I've made it:

    $.ajaxPrefilter( 'text', function( options ) { options.crossDomain = true; }); 
    $.ajax({ url: source, type: 'GET', dataType: 'text'
    

    Make it working in firefox, chrome and IE to load a local file ( not through any server )

    I was personnaly lacking this parameter which target api 16 at least ( wondering if any other parameter could target any older API )

    mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    

    thanks

    0 讨论(0)
提交回复
热议问题