[AC-5124] Ti.WKWebView failed ajax
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Needs more info |
Resolution Date | 2017-08-08T19:49:27.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Appcelerator Modules |
Labels | n/a |
Reporter | hakaniemi |
Assignee | Shak Hossain |
Created | 2017-08-03T07:46:12.000+0000 |
Updated | 2019-06-28T10:52:14.000+0000 |
Description
Ti.WKWebView failed with the code below. Ti.UI.WebView will work fine.
html = '<!DOCTYPE html><html><head><title>Local HTML</title><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script></head><body>';
html += '<a href="javascript:void()" id="btn" style="font-size:50px;">Click</a>';
html += '<script>$("#btn").on("click", function () {$.ajax({url:"https://google.com", cache:false, dataType:"html"}).done(function (json, textStatus, jqXHR) {alert(json)}).fail(function (jqXHR, textStatus, errorThrown) {alert(textStatus);});});</script>';
html += '</body></html>';
Hello, Thanks for reaching us. Would you mind if I request more details about your problem? What version of TiSDK, iOS and Ti.WKWebView do you have? Do you have any error log? Regards, Aminul
I am having the same problem when switching to Ti SDK 8.X.X WKWebView has replaced the UIWebview (i.e. Ti.UI.WebView is now WKWebView in Ti.SDK 8.X.X) I'm using Ti.SDK 8.0.2.GA Setting and loading html (as below) in webview should display an alert with data: {userId: 1, id: 1, title: "delectus aut autem", completed: false} which happens with Ti.SDK 7.X.X but not with 8.X.X html = '
Hi [~fahad86], is there a reason it needs to be AJAX and cannot be done internally with https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network-method-createHTTPClient
I make use of a webview based map which makes multiple calls to some APIs based on the panning of the user on the map. It would be very inefficient to have many bridge cross-overs.
[~fahad86] could you provide reproducible code so we can test it?
app.js
You can try the above. It needs to output an alert with json data (You can paste this in a browser and check the expected output: https://jsonplaceholder.typicode.com/todos)
We no longer need this as adding CORS headers ('Access-Control-Allow-Origin': '*') to our API's on our server helped solve this issue for us.