android - Difference between loadUrl and loadData with javascript -


I try to load an html page in an Android webview with an AJAX post request.

When I load the webview with LoadUrl, the javascript works fine, but when I try to load the load with data (I need it), I get an error: " NETWORK_ERR: XMLHttpRequest exception 101 ". This error looks like the basic problem of an access control.

ParseSupup function changes some strings into html pages with good strings. I check the data passing the load data and does not change the part of the script.

My Secret Function:

  Crate on Public Zero (Bundle Saved Instantstate) {super.onCreate (savedInstanceState); SetContentView (R.layout.main); String html = parsesup ("index.html"); SetContentView (R.layout.main); MyBrowser = (WebView) Find ViewById (R.id.mybrowser); MyBrowser.getSettings () setJavaScriptEnabled (true). MyBrowser.setWebViewClient (New MyWebViewClient ()); //myBrowser.loadUrl(file:///android_asset/index.html "); MyBrowser.loadDataWithBaseURL ("", html, "text / html", "utf-8", tap); }   

and my javascript code:

  $ Ajax setup ({contentType: "application / json; charset = utf-8", datatype: "json", async: false,}); $ .jax ({type: "post", url: "my url", data: 'my data', success: function (data) {// with some data activation, there are some implementations that result in message documents ("OK" + JSON.stringify (data)); console.log (data);}, error: function (data) {document.write ("KO" + JSON.Stringify (data)); console.log ( Data);}});   

thanks

Assume that, android when You call load data, and say android.webkit.WebView.loadUrl , then from webkit.WebView.loadDataWithBaseURL .

, the only difference between them, the loadURL references a webkit with the URL you set. On the other hand, the load data renders the WebKit, it comes from the source code parameter, and the baseURL There is also a parameter.

The JavaScript error message you receive is mostly related when you try to cross domain ajax request. This sounds more appropriate for your case because the only difference between your methods is that one of them seems to be a real URL, some have dynamically created a webpage, there is no solid URL.

Any other

"... to solve the relative URL of the original URL and to apply the same basic policy of Javascript, both are used is."

And the settings with your base parameters can give us clues about this issue.

Some dummy domain names or a domain that you own the baseURL, and try to include this domain at this JavaScript AJAX resource endpoint too. Such as:

  myBrowser.loadDataWithBaseURL ("http: // mydomain /", html, "text / html", "utf-8", tap);   

and on JavaScript:

  $ Ajax ({type: "POST", url: "http: // mydomain / my url", data: 'My data', success: function (data) {// do some action here with data variable, resulting in message document Write ("OK" + JSON.stringify (data)); console.log (data);}, error: function (data) {document.write ("KO" + JSON.stringify (data)); console Log (data);}});    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -