2016-09-26 3 views
0

도움을 주셔서 감사합니다. Freegeoip을 통해 사용자의 위치를 ​​기반으로 사용자를 리디렉션하려고 할 때 몇 가지 문제를 실험하고 있습니다. 당신은 간단하지만 난 작동 얻을 할수 없어위한스페인에서 사용자를 검색 할 때 다른 페이지로 리디렉션

이 될 수는 behaivour은 다음과 같아야합니다

모든 방문자가 스페인어 웹 사이트 www.theWeb.es로 이동하지만, 밖으로부터 그 사람 브라우저 스페인은 국제 페이지 (www.theInternationalWeb.com)로 리디렉션되어야합니다.

코드 : 시간에 대한

<script> 
    jQuery.ajax({ url: 'https://www.freegeoip.net/json/', 
    type: 'POST', 
    dataType: 'jsonp', 
    success: function(location) { 
     if (location.country_code === 'ES') { 
     // Do nothing because the user is already in the spanish Store. 
     else { 
     // if the user is not in Spain the send him to the international store. 
      window.top.location.href = 'http://theInternationalWeb.com'; 
     } 
    } }}); 
    </script> 

감사합니다.

Addittional 정보 :

국제 웹 사이트는 또한 스페인어 웹 사이트에 스페인어 사용자를 리디렉션하고, 그것이 저를 리디렉션 때문에 (내가 스페인에있는 AM)마다 잘하고있는 것 같다

<script> 


    jQuery.ajax({ 
    url: 'https://www.freegeoip.net/json/', 
    type: 'POST', 
    dataType: 'jsonp', 
    success: function(location) { 
    if (location.country_code === 'ES') { 
     // Redirect him to the Spanish store. 
     window.top.location.href = 'http://myWeb.es';} 
    }}); 

</script> 

중요 :

코드를 확인하고 내가 가지고있는 location.country_code를 감지하도록 경고하고 있습니다. 그러면 jsonp가 스페인의 스페인어 코드 대신 프랑스 국가 코드 FR을 제공하고있는 것으로 보입니다. 그래서 문제는 코드가 아니라 FreeGeoIP이 제공하는 정보입니다. 왜 그 사람이 누군지 압니까?

+1

'입력 : 'POST', dataType와 'JSONP는','- JSONP 형식은 GET 요청을 요구한다. jQuery는 이것을 POST 요청으로 만드는 작업을 무시합니다. – Quentin

+0

콘솔에서 어떤 오류가 발생합니까? –

+0

브라우저의 개발자 도구에서 콘솔을 사용해 보셨습니까? 문제의 원인 인 기본 구문 오류가 몇 가지 있습니다. – Quentin

답변

-1

사용 type:'GET'

jQuery.ajax({ url: 'https://www.freegeoip.net/json/', type: 'GET', dataType: 'jsonp', success: function(location) { if (location.country_code === 'ES') { // Do nothing because the user is already in the spanish Store. else { // if the user is not in Spain the send him to the international store. location.href = 'http://theInternationalWeb.com'; } } }});

+0

'dataType'은''jsonp "'이며, 이는 자동적으로'type :"GET "'을 강제 할 것입니다. JSONP 요청이있을 때'type'을 (어떤 값으로) 설정해도 효과가 없습니다. – Quentin

+0

@Quentin 감사합니다 –

+0

설명을위한 @Quentin 감사합니다 – Roberto