Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error CORS Access-Control-Allow-Origin #1

Open
mazipan opened this issue Dec 18, 2017 · 20 comments
Open

Error CORS Access-Control-Allow-Origin #1

mazipan opened this issue Dec 18, 2017 · 20 comments

Comments

@mazipan
Copy link

mazipan commented Dec 18, 2017

Error when trying to hit https://sites.google.com/macros/exec?service=AKfycbx_-gZbLP7Z2gGxehXhWMWDAAQsTp3e3bmpTBiaLuzSDQSbIFWD&menu=nama_produk&query=abc via httpclient.

I use axios as httpclient.

@mazipan
Copy link
Author

mazipan commented Dec 18, 2017

I use Cek Produk Halal MUI Api

@bachors
Copy link
Owner

bachors commented Dec 18, 2017

Kalo menggunakan javascript harus menggunakan callback om, ini contoh menggunakan jquery https://github.com/bachors/Ygrab.js/blob/master/js/ygrab.js

@mazipan
Copy link
Author

mazipan commented Dec 18, 2017

JSONP kali maksudnya ya om ?

@bachors
Copy link
Owner

bachors commented Dec 18, 2017

Iya om @mazipan jsonp 👍

@mazipan
Copy link
Author

mazipan commented Dec 18, 2017

Btw ini project yang sedang saya coba bikin pake API tersebut https://github.com/mazipan/cek-halal

Contoh request yang saya bikin ada di https://github.com/mazipan/cek-halal/blob/master/src/pages/Search.vue#L107

@bachors
Copy link
Owner

bachors commented Dec 18, 2017

Mantap om @mazipan ijin fork untuk belajar vue 👍

@mazipan
Copy link
Author

mazipan commented Dec 18, 2017

Sekarang malah dapat error ini

Refused to execute script from 'https://sites.google.com/macros/exec?service=AKfycbx_-gZbLP7Z2gGxehXhWMWDAAQsTp3e3bmpTBiaLuzSDQSbIFWD&menu=nama_produk&query=abc&callback=__jp1' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

Pake library ini https://www.npmjs.com/package/jsonp

@mazipan
Copy link
Author

mazipan commented Dec 18, 2017

screen shot 2017-12-18 at 7 09 27 pm
LIhat networknya aneh ya.
Jadi 3 request.
Yang pertama dapat response 307, kedua 302 baru 200.

@bachors
Copy link
Owner

bachors commented Dec 18, 2017

ini conto menggunakan callback jquery

`GS('abc', function(arr) {
alert(arr[0].title);
}) ;

function GS(a, b) {
$.getJSON("https://script.google.com/macros/s/exec?query=" + a + "&service=AKfycbx_-gZbLP7Z2gGxehXhWMWDAAQsTp3e3bmpTBiaLuzSDQSbIFWD&callback=?",function(c){
b(c.data);
});
}`

@mazipan
Copy link
Author

mazipan commented Dec 18, 2017

Ini bisa jalan om ? Sudah dicoba kah ?
Saya kok curiganya gara2 di redirect URL nyari2 ke url lain.

@mazipan
Copy link
Author

mazipan commented Jan 12, 2018

Udah nyoba pake jQuery getJSON

let path = `https://sites.google.com/macros/exec?service=AKfycbx_-gZbLP7Z2gGxehXhWMWDAAQsTp3e3bmpTBiaLuzSDQSbIFWD&menu=${this
        .selectedMenu.value}&query=${this.searchText}&cb=?`

$.ajaxSetup({ dataType: 'jsonp' })
$.getJSON(path, function (json) {
   console.log(JSON.stringify(json))
})

Dapat response ini
screen shot 2018-01-12 at 4 51 03 pm

Ada ide kah om @bachors ?

@bachors
Copy link
Owner

bachors commented Jan 24, 2018

o'iya lupa om belum mengatur code callback di google script.y , sekarang mah sudah bisa 👍 http://bachors.com/code/produk-halal-api-javascript

@mazipan
Copy link
Author

mazipan commented Jan 25, 2018

Masih belum bisa nih om @bachors :-(

@mazipan
Copy link
Author

mazipan commented Jan 30, 2018

Kemungkinan karena content-type nya salah om @bachors.
Kalo jsonp harusnya sih content-type nya javascript bukan json.

*cmiiw

@bachors
Copy link
Owner

bachors commented Jan 30, 2018

Sudah bener kok om content-type nya mah javscript :)
ini saya coba pake vue http://bachors.com/code/cek-halal-vue

@mazipan
Copy link
Author

mazipan commented Jan 30, 2018

Kok di saya dua duanya gak mau jalan ya demo yang dibuat diatas

@bachors
Copy link
Owner

bachors commented Jan 30, 2018

Dibukanya lewat smartphone ya om?

@mazipan
Copy link
Author

mazipan commented Jan 30, 2018

Iya, gak bisa ya ?

@mazipan
Copy link
Author

mazipan commented Jan 31, 2018

screen shot 2018-01-31 at 9 34 53 am

Screenshoot, access from desktop

@mazipan
Copy link
Author

mazipan commented Jan 31, 2018

screen shot 2018-01-31 at 9 36 50 am

Other demo screenshoot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants