javascript php 传值,js 传值到 PHP 有关问题
js 傳值到 PHP 問題
說一下我的需求:通過點擊button的時候,去通過php查找指定日期的數據庫當中的數據,
function?load_point(date)?{
//?Change?this?depending?on?the?name?of?your?PHP?file
downloadUrl("phpsqlajax_genxml2.php",?function(data)?{
//alert("downloadUrl1");
var?xml?=?data.responseXML;
var?markers?=?xml.documentElement.getElementsByTagName("marker");
var?polyOptions?=?{
strokeColor:?'#000000',????//?顏色
strokeOpacity:?1.0,????//?透明度
strokeWeight:?2????//?寬度
}
var?poly?=?new?google.maps.Polyline(polyOptions);
poly.setMap(map);????//?裝載
//alert("downloadUrl2");
for?(var?i?=?0;?i?
var?name?=?markers[i].getAttribute("name");
var?address?=?markers[i].getAttribute("address");
var?type?=?markers[i].getAttribute("type");
var?point?=?new?google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var?html?=?""?+?name?+?"?
"?+?address;
//var?icon?=?customIcons[type]?||?{};
var?path?=?poly.getPath();????//獲取線條的坐標
path.push(point);????//為線條添加標記坐標
//生成標記圖標
var?marker?=?new?google.maps.Marker({
position:point
//????map:?map,
//icon:?"http://labs.google.com/ridefinder/images/mm_20_green.png"
});
}
});
}
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);
}
下面是phpsqlajax_genxml2.php
$username="root";
$password="";
$database="data";
function?parseToXML($htmlStr)
{
$xmlStr=str_replace('
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return?$xmlStr;
}
//?Opens?a?connection?to?a?MySQL?server
$connection=mysql_connect?('localhost',?$username,?$password);
if?(!$connection)?{
die('Not?connected?:?'?.?mysql_error());
}
//?Set?the?active?MySQL?database
$db_selected?=?mysql_select_db($database,?$connection);
if?(!$db_selected)?{
die?('Can\'t?use?db?:?'?.?mysql_error());
}
//?Select?all?the?rows?in?the?markers?table
$query?=?"SELECT?*?FROM?markers?WHERE?1";
$result?=?mysql_query($query);
if?(!$result)?{
die('Invalid?query:?'?.?mysql_error());
}
header("Content-type:?text/xml");
//?Start?XML?file,?echo?parent?node
echo?'';
//?Iterate?through?the?rows,?printing?XML?nodes?for?each
while?($row?=?@mysql_fetch_assoc($result)){
//?ADD?TO?XML?DOCUMENT?NODE
echo?'
echo?'name="'?.?parseToXML($row['name'])?.?'"?';
echo?'address="'?.?parseToXML($row['address'])?.?'"?';
echo?'lat="'?.?$row['lat']?.?'"?';
echo?'lng="'?.?$row['lng']?.?'"?';
echo?'type="'?.?$row['type']?.?'"?';
echo?'/>';
}
//?End?XML?file
echo?'';
?>
現在想怎么能把date值傳遞到phpsqlajax_genxml.php
------解決思路----------------------
downloadUrl("phpsqlajax_genxml2.php?date="+new?Date-0,?function(data)?{
....
后面加一個當前時間刻度的參數
php?訪問?這個?$GET['date']?就可以了
總結
以上是生活随笔為你收集整理的javascript php 传值,js 传值到 PHP 有关问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 年终奖纳税方式变了有什么影响 年终奖纳税
- 下一篇: php 接口缓存,php写的一个缓存接口