WHAT'S NEW?
Loading...

Cordova + Jquery mobile: ga bisa ambil data lewat Ajax


Muter muter mbah gugel nyari kenapa ga bisa ngambil data dari server lewat ajax call dari aplikasi android yg dibikin pake cordova, ternyata solusinya cukup simpel saja :D

Error yg muncul di log adalah:
Refused to connect to 'http://fachrul.net/' because it violates the following Content Security Policy directive: "default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback.
dan
cordova Refused to connect to because it violates the following Content Security Policy directive: "default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'". Note that 'connect-src' was not explicitly set, so 'default-src' is used as a fallback. 

Solusinya setelah baca dari artikel ini:
http://www.html5rocks.com/en/tutorials/security/content-security-policy/
https://github.com/apache/cordova-plugin-whitelist#content-security-policy

cukup menambahkan meta tag di dalam file .html doank, diatas semua meta tag, contohnya kayak gini:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src 'self' http://fachrul.net">
Ganti link merah ke domain yg km mau.

Keterangan connect-src membatasi domain yang bisa kamu lakukan koneksi lewat XHR, WebSockets, ataupun EventSource

0 comments:

Post a Comment