2
    <!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”不允许访问”。

4

2 回答 2

2

您正在尝试执行XMLHttpRequest(AJAX)到另一个域。

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

有关详细信息,请参阅: http ://en.wikipedia.org/wiki/Cross-origin_resource_sharing

于 2014-01-07T14:11:15.110 回答
-1

您在线缺少分号:

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

于 2017-05-18T13:57:31.200 回答