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

1 comment: Leave Your Comments

  1. Alright...

    What I'm going to tell you might sound really creepy, and maybe even kind of "strange"

    WHAT if you could just push "Play" to listen to a short, "musical tone"...

    And suddenly bring MORE MONEY to your LIFE??

    And I'm talking about BIG MONEY, even MILLIONS of DOLLARS!!!

    Sound too EASY?? Think it's IMPOSSIBLE?!?

    Well, I've got news for you...

    Many times the most magical miracles life has to offer are also the EASIEST!!!

    In fact, I'm going to PROVE it to you by letting you PLAY a real-life "magical money-magnet tone" I've produced...

    And TOTALLY FOR FREE

    YOU just click "Play" and watch as your abundance angels fly into your life... starting so fast, you will be surprised...

    GO here to PLAY this magical "Miracle Money-Magnet Tone" - as my gift to you!!!

    ReplyDelete