nnaku
I'm object-oriented!
- Liittynyt
- 28.11.2016
- Viestejä
- 773
Koodi:fetch('http://192.168.1.8/request?S_227_85', { mode: 'no-cors' }) .then(res => res.text()) .then(teksti => { alert(teksti); })
Nyt haluttu string ilmestyy responseen ennen alertin kuittaamista, mutta ei tule mukaan alert-ruutuun.
Kuten sanoin nykyaikaiset selaimet estää corsit.
fetch mode 'no-cors' voit tehdä kutsun, ja saada paluuna statuksen, mutta responseen ei sallita pääsyä.
no-cors — Prevents the method from being anything other than HEAD, GET or POST, and the headers from being anything other than simple headers. If any ServiceWorkers intercept these requests, they may not add or override any headers except for those that are simple headers. In addition, JavaScript may not access any properties of the resulting Response. This ensures that ServiceWorkers do not affect the semantics of the Web and prevents security and privacy issues arising from leaking data across domains.
Request.mode
