oracle / cordova-plugin-wkwebview-file-xhr

Cordova Plugin for WebView File XHR
Universal Permissive License v1.0
138 stars 120 forks source link

XHR load local file synchronization #78

Closed ghost closed 3 years ago

ghost commented 3 years ago

Dear @All, At this moment, when use this plugin, I cannot load local file via XHR synchronization as below: xhttp.open("GET", filePath, false); xhttp.send(null); var text = xhttp.responseText; Is this issue? Thank you so much.

manish2788 commented 3 years ago

@taxuangiao No such issue exists as reported by you. Plugin works fine for synchronous request as well.

ghost commented 3 years ago

@manish2788 Thanks. However, I retry with synchronous XHR request and It is not OK. But I update to asynchronous XHR request, I could load file content. So please check again.

manish2788 commented 3 years ago

@taxuangiao Can you please share a sample cordova app demonstrating the issue you are facing.

ghost commented 3 years ago

@manish2788 there are source code to load file var xhr = new XMLHttpRequest(); xhr.open("GET", "js/test.txt", false); xhr.send(); var data = xhr.responseText; if (data) { alert(data); } else { alert("ERROR"); } the result is show alert "ERROR"

manish2788 commented 3 years ago

@taxuangiao Please go through https://javascript.info/xmlhttprequest to understand how to create an XMLHttpRequest request and get a response. No issue with the plugin.

ghost commented 3 years ago

@manish2788 , with above code, I tried remove this plugin and build on cordova-ios@4 (UIWebView) and it is OK. I think the plugin not support synchronous XHR request.

gvanmat commented 3 years ago

On the ios side the http request, response is synchronous but the communication with the plugin is asyc. The client registers a callback handler. At the time this was originally development, Js es6 await/async was not an option. It might be possible now for the send to return a promise and the client could call await xhr.send(). Kind of a JS impl restriction.

On Thu, Jan 21, 2021, 3:26 AM Manish Kumar notifications@github.com wrote:

@taxuangiao https://github.com/taxuangiao Please go through https://javascript.info/xmlhttprequest to understand how to create an XMLHttpRequest request and get a response. No issue with the plugin.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/oracle/cordova-plugin-wkwebview-file-xhr/issues/78#issuecomment-764535984, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEGCGU3YLX4DDPJM42KEI7TS276LVANCNFSM4WHGEROA .