我使用jvector map创建地图。它工作得很好。现在我想从数据库中获取国家deatails。我用mysql代码创建了php连接
database.php中
<?php
$host = "localhost";
$port = 3306;
$user = "root";
$password = "";
$dbname = "mydatabase";
$country = $_POST['canada'];
$con = new mysqli($host, $user, $password, $dbname, $port, $socket)
or die ('Could not connect to the database server' . mysqli_connect_error());
//$con->close();
$query = "SELECT countryId, country, pdogcoregion, comments, ccl, category
FROM countrydetails
WHERE country='canada' ";
$countrydetails = '';
$stmt->bind_param('s', $countrydetails);
if ($stmt = $con->prepare($query)) {
$stmt->execute();
$stmt->bind_result($countryId, $country, $pdogcoregion, $comments, $ccl, $category);
while ($stmt->fetch()) {
}
$stmt->close();
}
?>
这是我的HTML代码:
<script src="assets/jquery-jvectormap-world-mill-en.js"></script>
<script>
jQuery.noConflict();
jQuery(function(){
var $ = jQuery;
$('#focus-single').click(function(){
$('#map1').vectorMap('set', 'focus', {region: 'AU', animate: true});
});
$('#focus-multiple').click(function(){
$('#map1').vectorMap('set', 'focus', {regions: ['AU', 'JP'], animate: true});
});
$('#focus-coords').click(function(){
$('#map1').vectorMap('set', 'focus', {scale: 7, lat: 35, lng: 33, animate: true});
});
$('#focus-init').click(function(){
$('#map1').vectorMap('set', 'focus', {scale: 1, x: 0.5, y: 0.5, animate: true});
});
$('#map1').vectorMap({
map: 'world_mill_en',
panOnDrag: true,
focusOn: {
x: 0.5,
y: 0.5,
scale: 1,
animate: true
},
series: {
regions: [{
scale: ['#688FA0'],
normalizeFunction: 'polynomial',
values: {
}]
},
onRegionClick: function (event, code) {
var map = $('#map1').vectorMap('get', 'mapObject');
var name = map.getRegionName(code);
//alert(name);
var labelText='Not Assign';
// get from DB using ajax
$.ajax({
type: "POST",
url: 'database.php',
data: {country: 'canada'},
dataType: "text",
success: function(data){
alert(data);
});
});
});
如何使用mysql php数据库连接ajax?请帮助..........
答案 0 :(得分:0)
你需要在database.php上回应一些东西,以便javascript接收php动作的结果。输出的格式可以是您想要的,但需要回显或打印。