CodingTrain / CodingTrain/Intro-to-Data-APIs-JS

1.1 fetch: Same Origin Policy problem

Đang mở
#43 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
HTML
Star
759
Fork
592
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Just starting! And already hitting a minor roadblock. Both the code I wrote and the [code from Github](https://github.com/CodingTrain/Intro-to-Data-APIs-JS/blob/source/module1/01_fetch_image/index.html) lead to an error in my browser when it tries to fetch the image:

> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///home/bbausch/js-working-with-data/1.1-fetch/rainbow.jpg

This is Firefox 68 on Xubuntu. I solved the problem by hosting the picture on a web server (the node.js/express.js web server from video 2.1 :)), but I wonder why I am the only one with this problem?

**EDIT**: Dan uses live-server, and on its [web site](https://www.npmjs.com/package/live-server), I read

> AJAX requests don't work with the file:// protocol due to security restrictions, i.e. you need a server if your site fetches content through JavaScript.

So I feel validated! But my question remains - is everybody using live-server or are there other methods to get around cross-origin problems?

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với ví dụ fetch 1.1 được liên kết và lỗi Firefox với file:// đã được báo cáo, sau đó so sánh với các cách tiếp cận dùng live-server và Node.js/Express được đề cập trong issue. Công việc được xem là hoàn tất khi đã ghi lại cách được hỗ trợ để chạy ví dụ và giải thích hạn chế liên quan của trình duyệt cũng như các phương án thay thế.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
express, javascript, node.js
Lĩnh vực
web-dev
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.