2015-02-06 2 views
0

Google Place API를 사용하여 가장 가까운 위치에 대한 제안을 받고 있습니다.Google Place API - jQuery JSON 수신 데이터 유지하기

서버에서 데이터를 가져올 수있었습니다.

는 내가 jQuery를 구문 분석하여 데이터를 얻기 위해 수행 한 어떤 this-

{ 
    "predictions" : [ 
     { 
     "description" : "Australia", 
     "id" : "3ba963f8de67dc16df0a8de60e46418338a3181a", 
     "matched_substrings" : [ 
      { 
       "length" : 1, 
       "offset" : 0 
      } 
     ], 
     "place_id" : "ChIJ38WHZwf9KysRUhNblaFnglM", 
     "reference" : "CjQhAAAAlf04PlAgVJSzXXBUwZc0JGNjk5I9hsWHkvWwfuY_U4bkR3hm2lC4EN6fV4KOXr9PEhD5vhvmJOucMwDiwRaYJ0RAGhQofmdPwvnV4qHFefKAu0Anw110WQ", 
     "terms" : [ 
      { 
       "offset" : 0, 
       "value" : "Australia" 
      } 
     ], 
     "types" : [ "country", "political", "geocode" ] 
     }, 
     { 
     "description" : "Argentina", 
     "id" : "dcaa0dffd352dfaaa3dc73dd1dbf3153708637ef", 
     "matched_substrings" : [ 
      { 
       "length" : 1, 
       "offset" : 0 
      } 
     ], 
     "place_id" : "ChIJZ8b99fXKvJURqA_wKpl3Lz0", 
     "reference" : "CjQhAAAAO1RnJcq4Dky5uLQFHCULfP6VzbklXYCiR_DDuJMJxf5wFbTXVnHM7bn7ZSlxsR7IEhC_HlGxn8JeuC2h86S2EIpSGhRddclDM07Acre3NSiTWJoClMNtKQ", 
     "terms" : [ 
      { 
       "offset" : 0, 
       "value" : "Argentina" 
      } 
     ], 
     "types" : [ "country", "political", "geocode" ] 
     }, 
     { 
     "description" : "Austria", 
     "id" : "e16f8e9f2a60f60a0881c41488ff3869e4f938a4", 
     "matched_substrings" : [ 
      { 
       "length" : 1, 
       "offset" : 0 
      } 
     ], 
     "place_id" : "ChIJfyqdJZsHbUcRr8Hk3XvUEhA", 
     "reference" : "CiQfAAAAXX_lF6oxms4MgmajAkQabO3drGaCf04EHArvaGV3UTISEFulfBYy0rmrSxPIb1JLY_0aFJ2UqN170fR7OjOGAF3v3vZqO21i", 
     "terms" : [ 
      { 
       "offset" : 0, 
       "value" : "Austria" 
      } 
     ], 
     "types" : [ "country", "political", "geocode" ] 
     } 
    ], 
    "status" : "OK" 
} 

같은 서버에서 응답을

$.ajax(
{ 
    url: Auto_Complete_Link, 
    type: "GET", 
    dataType: 'jsonp', 
    cache: false, 
    crossDomain: true, 
    /*data: JSON.stringify(somejson),*/ 
    success: function (response) 
    { 
     $.each(response, function(i, field) 
     { 
      console.log(field + " <=> "+ i); 
     }); 
    }, 
    error: function (xhr, status) 
    { 
     console.error("not connecting to google server"); 
    } 
}); 

그래서 코드의 파싱 부분은 금하지이 IT-이

$.each(response, function(i, field) 
{ 
    console.log(field + " <=> "+ i); 
}); 

하지만

,369라는 오류가 발생하고 같은

Uncaught SyntaxError: Unexpected token :

오류 사람이이 문제를 해결하는 데 도움 주실 래요 - 그것을

22

같은 JSON입니까?

도움을 주셔서 미리 감사드립니다.

$.ajax(
{ 
    url: Auto_Complete_Link, 
    type: "GET", 
    dataType: "json", 
    contentType: "application/json; charset=utf-8", 
    cache: false, 
    crossDomain: true, 
    success: function (response) 
    { 
     $.each(response, function(i, field) 
     { 
      console.log(field + " <=> "+ i); 
     }); 
    }, 
    error: function (xhr, status) 
    { 
     console.error("not connecting to google server"); 
    } 
}); 
+0

는 Google 지역 정보 API 오히려 JSON보다 JSONP를 반환 당신이 긍정적 : – timothyclifford

+0

내가받는 것은 여기에 있습니다. –

+0

내 생각에 JSONP –

답변

1

은 당신의 자바 스크립트를 변경해보십시오?
관련 문제