xml 문서를 구문 분석하는 PHP 스크립트에서 일부 결과를 얻으려면 jquery ajax를 사용하고 있습니다. 그 아약스는 내가 그 문제는 그게 내 문제 야 에 의해 만들어진 div에서, 구글 API에서지도를 보여 whant 내 전화)입니다.div에로드 된 Google지도로드 ajax
ajax 호출 후 PHP에서 생성 된 <div id="map-canvas">
에지도 API를로드 할 수 있습니까 ??
PHP 파일
... $xmlData = simplexml_load_file("using an http service");
echo "<div id='map-canvas'></div>"; //LOAD MAPP HERE!
echo "<ul>";
foreach($xmlData->StopTimes->StopTime as $stopTime){
echo "<li>",$stopTime->attributes()->Hour,"</li>";
}
echo "</ul>";
}
AJAX 파일
...
//station click, show next stops
$('.station_link').click(function(){
var station_text = $(this).text();
$.ajax({ //make the ajax call
type: "POST", //use POST/GET
url: "../server_side/nextStop.php", //file to send data
data: {poststation : station_text}, //postlink -> php($_POST) value/text -> jquery var value
success: function(data){ //on success, do something
$('#next_stop').html(data);
$('#next_stop').show();
//Google maps API
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=TRUE_OR_FALSE&callback=initialize";
document.body.appendChild(script);
}
loadScript();
}
});
});
});
이 내가 시도 (그리고 더 많은 : p)를 한 것입니다,하지만 난 심지어는 단지 잘못 알고 해달라고 .
어떤 도움이나 조언을 부탁드립니다.
- UPDATE -이 같은
로 간단한 :
자바 스크립트 파일
//station click, show next stops
$('.station_link').click(function(){
var station_text = $(this).text();
$.ajax({ //make the ajax call
type: "POST", //use POST/GET
url: "../server_side/nextStop.php", //file to send data
data: {poststation : station_text}, //postlink -> php($_POST) value/text -> jquery var value
success: function(data){ //on success, do something
$('#next_stop').html(data);
$('#next_stop').show();
// Google maps API
var mapOptions = {
center: new google.maps.LatLng(37.7831,-122.4039),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
});
});
});
그리고 바로이 <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
에 HTML 파일을 추가.
그건 내가 바라는대로, <div id="map-canvas">
을로드해야합니다.
어쨌든 도움을 청하십시오! 미안 내가 일찍이 내 요점을지지하지 않았다면 나는 조금 초보자이다.)
아쉽다. 로드하는 데 2000 밀리 초가 걸리면 어떻게됩니까? – BenLanc