javascript - ajax request xml from php -
i have google map, gets markers loaded based on date variable, in php. default date current date. want date changeable, through form. on page map is, have form, users can select date, , want map reload markers based on date selected. have onchange event call mytest(); function, re-load map. can't work, when date changed, nothing happens. here code.
javascript
function mytest() { var map = '' function mymap(){ var im = 'http://www.robotwoods.com/dev/misc/bluecircle.png'; var custommarker = 'http://findmyyard.com/images/markericon.png'; if(navigator.geolocation){ navigator.geolocation.getcurrentposition(locate); } else { alert('please enable "location sharing"') } function locate(position){ var mylatlng = new google.maps.latlng(position.coords.latitude, position.coords.longitude); var mapoptions = { zoom: 12, center: mylatlng, maptypeid: google.maps.maptypeid.roadmap, zoomcontrol: true, streetviewcontrol: false, } var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); var usermarker = new google.maps.marker({ position: mylatlng, map: map, icon: im }); var infowindow = new google.maps.infowindow; var date = document.getelementbyid('finddate').value; // change depending on name of php file downloadurl("phps/xmltest.php"+ date, function(data) { var xml = data.responsexml; var markers = xml.documentelement.getelementsbytagname("marker"); (var = 0; < markers.length; i++) { var name = markers[i].getattribute("name"); var address = markers[i].getattribute("address"); var dt1 = markers[i].getattribute("date1"); var dt2 = markers[i].getattribute("date2"); var dt3 = markers[i].getattribute("date3"); var tm1 = markers[i].getattribute("time1"); var tm2 = markers[i].getattribute("time2"); var tm3 = markers[i].getattribute("time3"); var html = "<b>" + name + "</b> <br/>" + "date of yard sale: " + dt1 + ' ' + tm1 + ' ' + dt2 + ' ' + tm2 + ' ' + dt3 + ' ' + tm3 + ' ' + "<br/>" + address; var point = new google.maps.latlng( parsefloat(markers[i].getattribute("lat")), parsefloat(markers[i].getattribute("lng"))); var marker = new google.maps.marker({ map: map, position: point, icon: custommarker }); bindinfowindow(marker, map, infowindow, html); } }); function bindinfowindow(marker, map, infowindow, html) { google.maps.event.addlistener(marker, 'click', function() { infowindow.setcontent(html); infowindow.open(map, marker, html); }); } 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() {} } }}
php - xmltest.php
<?php $date = $_get['date']; if($date == "''" || $date == "today") { $date = date('m-d-y');} else {$date = $_get['date'];} $dom = new domdocument("1.0"); $node = $dom->createelement("markers"); $parnode = $dom->appendchild($node); // opens connection mysql server mysql_connect("localhost", "someuser", "somepw"); // set active mysql database $db_selected = mysql_select_db("registration2"); if (!$db_selected) { die ('can\'t use db : ' . mysql_error()); } // select rows in markers table $query = "select * registered2 dateone = '$date' or datetwo = '$date' or datethree = '$date'"; $result = mysql_query($query); if (!$result) { die('invalid query: ' . mysql_error()); } header("content-type: text/xml"); // iterate through rows, adding xml nodes each while ($row = @mysql_fetch_assoc($result)){ // add xml document node $node = $dom->createelement("marker"); $newnode = $parnode->appendchild($node); $newnode->setattribute("name",$row['name']); $newnode->setattribute("address", $row['address']); $newnode->setattribute("lat", $row['latitude']); $newnode->setattribute("lng", $row['longitude']); $newnode->setattribute("date1", $row['dateone']); $newnode->setattribute("date2", $row['datetwo']); $newnode->setattribute("date3", $row['datethree']); $newnode->setattribute("time1", $row['timeone']); $newnode->setattribute("time2", $row['timetwo']); $newnode->setattribute("time3", $row['timethree']); } echo $dom->savexml(); ?>
please me out , let me know i'm doing wrong.
all needed change name of var "date" else.
Comments
Post a Comment