2017-04-05 48 views
0

如何將Access-Control-Allow-Origin: *添加到Shiny應用程序中?R Shiny - 如何添加Access-Control-Allow-Origin:*

我想通過以下AJAX調用閃亮應用:

<div id='include-from-outside'></div> 
<script type='text/javascript'> 
    $.get('//127.0.1.1:3838/', {}, function(data, status, xhr) { 
     var updatedData = data.replace(/\/(images|stylesheets|javascripts|vendors|fonts)+/g, "http://127.0.1.1:3838/$1"); 

     $('#include-from-outside').html(updatedData); 
    }); 
</script> 

但我得到這個錯誤:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://127.0.1.1 ' is therefore not allowed access.

任何想法?

回答

1

我有同樣的問題。

簡單的方法是在google chrome中添加擴展名以允許使用CORS進行訪問。

https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en-US),只要你想允許訪問任何「訪問控制允許來源」頭請求

只啓用這個擴展。

+0

謝謝。但可能我們不能要求用戶添加。有光澤的確是一個糟糕的框架。太多限制! – laukok

+1

發生這種情況是因爲您正在向不同於您的頁面的域請求HttpRequest。你必須做這樣的事情。選中此鏈接[使用CORS](https://www.html5rocks.com/en/tutorials/cors/) – DragonBorn