Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at

故事扮演 提交于 2021-02-20 00:48:29

问题


I tried using a web app that would access h20 flow using REST API routes and when I tried to delete a frame (it would delete the frame after predicting), this happens:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://139.59.249.87:54321/3/Frames/1i3uso. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

I'm using ruby rails in order to build the web app. Any advice? I used this route: DELETE /3/Frames/{frame_id} and this coffee script is used:

deleteUploadFrame = (frame_id) ->
$.ajax
url: "http://139.59.249.87:54321/3/Frames/#{frame_id}"
method: 'DELETE'

This is the error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://139.59.249.87:54321/3/Frames/1i3uso. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

What should I do for this?


回答1:


Add these lines to application controller. This will fix your problem.

   after_filter :cors_set_access_control_headers

  def cors_set_access_control_headers
    headers['Access-Control-Allow-Origin'] = '*'
    headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
    headers['Access-Control-Request-Method'] = '*'
    headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
  end


来源:https://stackoverflow.com/questions/38454519/cross-origin-request-blocked-the-same-origin-policy-disallows-reading-the-remot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!