请求的资源上不存在“Access-Control-Allow-Origin”标头

时间:2014-01-07 14:03:46

标签: jquery jquery-mobile-ajax

    <!DOCTYPE html>
        <html>
            <head>
                <meta charset="utf-8" />
                <meta name="viewport" content="width=device-width, initial-scale=1" />
                <title>webservices example </title>
                <link rel="stylesheet" href="jquery.mobile-1.1.0.css" />
                <link rel="stylesheet" href="my.css" />
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
                <script type="text/javascript">
                    $(document).ready(function() {
                            $.ajax({
                                type:"GET",
                            url:"http://shoperola.com/Restaurant/foodysrest/sample",
                                 crossDomain: true,
                                 contentType: "application/json; charset=utf-8",

                                 dataType: "json",
xhrFields: {

       withCredentials: true
  },
             beforeSend: function (request) {

request.setRequestHeader("Access-Control-Allow-Origin: ", "*")
},
                                 success: function(data) {
                                                alert(data);
                                                },
                                 error: function(data) {
                                alert("Error in Processing-----" + data.status);
                                          }
                                });
                        });

                </script>
            </head>
        </html>

“XMLHttpRequest无法加载http://shoperola.com/Restaurant/foodysrest/sample?{}。请求的资源上没有'Access-Control-Allow-Origin'标头。因此不允许来源'http://:8088'访问”。

2 个答案:

答案 0 :(得分:2)

您正在尝试向其他域执行XMLHttpRequest(AJAX)

由于安全原因,这是受限制的。

了解更多详情,请参阅: http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

答案 1 :(得分:0)

你在网上缺少分号:

request.setRequestHeader(“Access-Control-Allow-Origin:”,“*”)