2017-06-30 4 views
-1

私は、ajaxを使用してURLからデータを取得しようとしています。しかし、そのエラーajaxからURLエラーからデータを取得するAccess Control-Allow-Origin

XMLHttpRequest cannot load http://examp.com/check/127.0.0.1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1' is therefore not allowed access. 

は、ここに事前に...

感謝を助けてください、私のコード、

var loc = window.location.hostname; 
var loca = encodeURIComponent(loc); 
$('#checked').remove(); 
$.ajax({url: 'http://examp.com/check/'+loca, success: function(result){ 
    $('#checked').remove(); 
    if(result !== ''){ 
     if(result !== 'nice'){ 
      if(result == 'bad'){ 
       var al = 'not registered'; 
       var bvh = 'exit'; 


       if($('.container').length){ 
        alert(al); 
        $('html').html(bvh); 
        setInterval(function(){alert(al)}, 15000); 
       } 
      } 
     } 
    } 
}}); 

です。

答えて

-1

このURLエンドポイントhttp://examp.com/check/'+locaには、Access-Control-Allow-Origin: *というヘッダーを含める必要があります。また、同じ質問 header('Access-Control-Allow-Origin: *');

:URLエンドポイントは、あなたのウェブサーバ上に位置し、あなたがPHPを使用している場合は、このコードを追加することができhow to bypass Access-Control-Allow-Origin?

+0

を私はこの 'ら:: ERR_CONNECTION_TIMED_OUT'を使用するとき、私はこのエラーを取得します –

関連する問題