【问题标题】:no 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '_example__' is therefore not allowed access请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin '_example__' 不允许访问
【发布时间】:2014-12-02 04:00:04
【问题描述】:

//

Blockquote 我正在尝试通过 Web API 访问 json 内容。我可以访问内容,但由于某种原因它给了我错误 :“没有‘Access-Control-Allow-Origin’标头出现在 请求的资源。因此不允许使用原点'http://localhost' 访问。”现在这意味着我必须启用一些 CORS 或通过 将内容移动到同一个域。

我不确定是否必须在以下位置启用它:源服务器(请求) 在这种情况下 localhost b:在外部服务器上或 c:我必须设置 在我的 ajax 调用中添加一些代码

请建议并指导正确的内容,因为我有点 ******* in 这方面。

<script>
        jQuery(document).ready(function() {
            jQuery('#34f8l4frywio').change(function(){
                if((jQuery("#34f8l4frywio").length < 0) || (jQuery("#vnkt3fpocr10").length < 0)){

                }else{
                    var newserial = jQuery("#34f8l4frywio").val();
                    var newmodel = jQuery("#vnkt3fpocr10").val();
                    jQuery.ajax({
                        url : 'http://example.com/xmlrpc/serial_json.php?serial='+ newserial+'&model='+ newmodel + '&format=json',

                        dataType: "text",
                        contentType: "text/plain",
                        xhrFields: {
                            withCredentials: false
                            }, 
                         //here it fails and gives the error
                        success: function(data) {
                            var json = $.parseJSON(data);

                                jQuery('#6bun045yhogr').val(json[0].warranty);
                                jQuery('#34f8l4frywio').val(json[0].serial);
                                jQuery("#vnkt3fpocr10").val(json[0].model);
                        }
                    });
                }
            });
        });
    </script>

【问题讨论】:

    标签: xmlhttprequest cors


    【解决方案1】:

    参考Angular.js No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access

    “Access-Control-Allow-Origin 设置在来自服务器的响应上,而不是在客户端请求上,以允许来自不同来源的客户端访问响应。”

    【讨论】:

      猜你喜欢
      • 2013-12-24
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-09
      • 2018-10-15
      • 2014-03-13
      相关资源
      最近更新 更多