2012-12-20 1 views
0

안녕하세요 저는 zipcode 필드에 jquery UI 자동 완성 플러그인을 사용하고 있습니다.geonames JSON 응답에서 미국 zipcode 만받을 수 있습니까?

jQuery UI 자동 완성 플러그인은 geonames.org의 JSON 응답을 사용합니다. 여기

응답을 얻을 내 코드입니다 : -

지금은
jQuery("#"+prefix+"_zip").autocomplete({ 

     source: function(request, response) { 
      jQuery.ajax({ 
       url: "http://ws.geonames.org/postalCodeSearchJSON", 
       dataType: "jsonp", 
       data: { 
        style: "full", 
        maxRows: 12, 
        postalcode_startsWith: request.term 
       }, 
       success: function(data) { 

        response(jQuery.map(data.postalCodes, function(item) { 
         return { 
          label: item.placeName + (item.adminCode1 ? ", " + item.adminCode1 : "") + ", " + item.postalCode + ", "+item.countryCode, 
          value: item.postalCode 
         } 
        })); 
             jQuery('.ui-autocomplete').css('width', '188px'); 
       } 
      }); 
     } 

, 우편 번호 필드에 내 커서를 놓고는 나에게 자동 완성 목록을 제시 한 후 모든 우편 번호를 입력 할 때 더를 입력하거나 우리가 jQuery 플러그인 말할 수에 대한 내가 입력 한 코드의 상대 값을 보여줍니다.

이제 사용자 지정 요구 사항이 하나 있습니다. 미국 우편 번호에 대해서만 JSON 응답을 받고 싶습니다.

우편 번호 입력란에 값을 입력하면 미국 관련 우편 번호가 자동 완성 목록으로 표시됩니다.

geonames.org에서 미국 zipcodes JSON 응답 만받는 방법을 알려줄 수 있습니까?

+0

JS에서 geonames 서비스와 통신하는 데 사용하는 코드를 공유하여 문제를 해결할 수 있습니까? –

+0

물론 Suhail 나는 내 코드 – Akki

+0

@ Suhail이 질문을 편집합니다 안녕하세요, 코드를 업로드했습니다. – Akki

답변

1

귀하의 URL에 나열되어 있습니다,

예 : 당신이 API는이 작업을 수행 할 수있는 멕시코와 미국의 모든 도시를 반환해야 할 경우 멕시코 http://ws.geonames.org/searchJSON?&country=MX

미국 http://ws.geonames.org/searchJSON?&country=US

뭔가도 쿨

http://ws.geonames.org/searchJSON?&country=US,MX&username=tpassolano

주이며, : geonames는 이제 사용자 이름이 필요합니다. 업데이트 된 API 호출

희망이 있습니다.

+0

geonames도 https를 지원합니다. –

0

당신은 약간 귀하의 요청을 수정하고 국가의 옵션을 추가 할 수 있습니다 : 우편 번호 검색

jQuery("#"+prefix+"_zip").autocomplete({ 
    source: function(request, response) { 
     jQuery.ajax({ 
      url: "http://ws.geonames.org/postalCodeSearchJSON", 
      dataType: "jsonp", 
      data: { 
       style: "full", 
       maxRows: 12, 
       postalcode_startsWith: request.term, 
       country: "US" 
      }, 
      success: function(data) { 
       response(jQuery.map(data.postalCodes, function(item) { 
        return { 
         label: item.placeName + (item.adminCode1 ? ", " + item.adminCode1 : "") + ", " + item.postalCode + ", "+item.countryCode, 
         value: item.postalCode 
        } 
       })); 
       jQuery('.ui-autocomplete').css('width', '188px'); 
      } 
     }); 
    } 
}); 

모든 옵션을 매개 변수로 나라를 전달할 수 GeoNames Web Services Documentation

관련 문제