Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5124] Ti.WKWebView failed ajax

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2017-08-08T19:49:27.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAppcelerator Modules
Labelsn/a
Reporterhakaniemi
AssigneeShak Hossain
Created2017-08-03T07:46:12.000+0000
Updated2019-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>';

Comments

  1. Aminul Islam 2017-08-06

    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
  2. Muhammad Ahmed Fahad 2019-06-21

    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 = 'Local HTML'; html += 'Click'; html += ''; html += ''; Please re-open this issue and please fix as soon as possible. This has been putting off my upgrade to 8.X.X for quite a long time. Or at least document on how a workaround can be implemented.
  3. Rene Pot 2019-06-21

    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
  4. Muhammad Ahmed Fahad 2019-06-24

    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.
  5. Rene Pot 2019-06-24

    [~fahad86] could you provide reproducible code so we can test it?
  6. Muhammad Ahmed Fahad 2019-06-25

    app.js
       // Some comments here
       public String getFoo()
       var window = Ti.UI.createWindow({
         width: Ti.UI.FILL,
         height: Ti.UI.FILL
       });
       
       var 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://jsonplaceholder.typicode.com/todos", cache:false, dataType:"json"}).done(function (json, textStatus, jqXHR){alert(json)}).fail(function (jqXHR, textStatus, errorThrown){alert(textStatus);});});</script>';
       html += '</body></html>';
       
       window.add(Ti.UI.createWebView({
         html: html,
         width: Ti.UI.FILL,
         height: Ti.UI.FILL
       });
       
       window.open();
       
    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)
  7. Muhammad Ahmed Fahad 2019-06-28

    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.

JSON Source