2014-01-07 46 views
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?{}。否‘訪問控制允許來源’標題存在於所請求的資源。原因'http://:8088'因此不被允許訪問「。否「訪問控制允許來源」標題存在於所請求的資源

回答

2

您正在嘗試執行XMLHttpRequest(AJAX)到另一個域。

由於安全原因,這受到限制。

詳細內容見: http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

+0

你意味着服務器沒有配置爲允許這個?因爲在客戶端,我認爲這是按照CORS中的建議實現的,使用xhrFields和證書,並使用ACAO設置標題。 –

0

你在網上失蹤分號:

request.setRequestHeader( 「訪問控制允許來源:」, 「*」)

相關問題