我希望有人能帮助我。
我正在使用 PHP、AJAX、JQUERY 和一个 XML 文件。
我想使用 AJAX(不刷新页面)动态更新 XML 文件的查询字符串,并从数据库中获取新的 XML 文件和新的结果......
我基本上把所有这些东西都准备好了,但不知道如何更新 XML 文件的参数。
所以基本上我想要一个链接或一个按钮,或者带有参数值的下拉列表
<button>Test1</button>
<button>Test2</button>
<button>Test3</button>
当我单击按钮 Test1 - 它应该将 XML 文件(在 JavaScript 中)设置为 page.php?q=test1 如果我单击 Test2 它应该将 page.php 更改为 page.php?q=test2
如何设置 XML 文件参数以根据正在提交的按钮的值进行更改,如果我可以将参数更新为按钮的值,我很好,并且可以进行刷新
XML 页面确实是一个 PHP 页面,它根据传递给页面的查询字符串生成 XML 格式的结果。
如果我手动将查询字符串更改为 page.php?q=test2 我确实会根据查询字符串获得结果,我只需要在点击时发生这种情况
这是我拥有的代码示例(更新了代码以显示确切示例)
<script>
var customIcons = {
events: {
icon: '/wp-content/uploads/gmaps/icons/car.png',
},
bar: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
google.maps.visualRefresh = true;
var panorama;
var entryPanoId = null;
function initialize() {
var xmap = new google.maps.LatLng(-26.245325,27.982386);
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, mapOptions);
google.maps.event.addDomListener(mapDiv, 'click', showAlert);
var mapOptions = {
center: xmap,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var infoWindow = new google.maps.InfoWindow;
downloadUrl("/wp-content/themes/geraldferreira/templates/phpsqlsearch_genxml.php",
function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var map_icon = markers[i].getAttribute("map_icon");
var map_desc = markers[i].getAttribute("map_desc");
var map_info_url = markers[i].getAttribute("map_info_url");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<h2>" + name + "</h2>"+map_desc + "<br/><b>Address:</b> "+ address+"<br/>More about<br/><button onclick='location.href=\""+map_info_url+"\"' class='btn btn-mini btn-info'>"+ name +"</button> <button class='btn btn-mini btn-info' onclick='toggleStreetView(this);'>Virtual Tour</button>";
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
panorama = map.getStreetView();
var panoOptions = {
position: xmap,
visible: true,
panoProvider: getCustomPanorama
};
panorama.setOptions(panoOptions);
var streetviewService = new google.maps.StreetViewService();
var radius = 100;
streetviewService.getPanoramaByLocation(xmap, radius,
function(result, status) {
if (status == google.maps.StreetViewStatus.OK) {
google.maps.event.addListener(panorama, 'links_changed',
function() {
createCustomLinks(result.location.pano);
});
}
});function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
}
function getCustomPanoramaTileUrl(pano, zoom, tileX, tileY) {
return "/wp-content/uploads/virtual_tours/"+pano+'/images/'+tileX+'-'+tileY+'.png';
}
function getCustomPanorama(pano) {
switch(pano) {
<?php
global $wpdb;
$virtual_tours = $wpdb->get_results( "SELECT * FROM wp_virtual_tours" );
foreach($virtual_tours as $virtual_tour){
echo "case '".$virtual_tour->id."': return {location: {pano: '".$virtual_tour->id."', description: '".$virtual_tour->virtual_tour_name." - ".$virtual_tour->id."', latLng: new google.maps.LatLng(-26.245325,27.982386)},links: [], copyright: 'Imagery (c) 2010 Google', tiles: {tileSize: new google.maps.Size(512, 512),worldSize: new google.maps.Size(4096, 2048),centerHeading: ".$virtual_tour->virtual_tour_centerheading.",getTileUrl: getCustomPanoramaTileUrl}}; break;";
}
?>
default:
return null;
}
}
function createCustomLinks(entryPanoId) {
var links = panorama.getLinks();
var panoId = panorama.getPano();
switch(panoId) {
<?php if ($_GET[virtualtour] != Null)
{
echo "case entryPanoId: links.push({heading: 310, description : 'Johannesburg Boat Show 2013', pano : '".$_GET["virtualtour"]."'}); break;";
}
elseif ($_GET[virtualtour] == Null){
echo "case entryPanoId: links.push({heading: 310, description : 'Johannesburg Boat Show 2013', pano : '90'}); break;";
}
?>
<?php
global $wpdb;
$virtual_tours = $wpdb->get_results( "SELECT * FROM wp_virtual_tours" );
foreach($virtual_tours as $virtual_tour){
echo ''.$virtual_tour->virtual_tour_links_code.'';
}
?>
default:
return;
}
}
function toggleStreetView() {
var toggle = panorama.getVisible();
if (toggle == false) {
panorama.setVisible(true);
} else {
panorama.setVisible(false);
}
}
function showAlert() {
/*window.alert('DIV clicked');*/
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
这是我需要在上面的代码中添加参数的 XML(PHP 文件)
downloadUrl("/wp-content/themes/geraldferreira/templates/phpsqlsearch_genxml.php"
因此,单击按钮时,我想phpsqlsearch_genxml.php?q=newvalue"
通过 Ajax 将参数传递给并刷新页面,而不是重新加载页面