如何调用ajax php数据库? [英] how to call ajax php database?

查看:61
本文介绍了如何调用ajax php数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jvector map.its中创建了Map。我做了很多自定义。现在我想从数据库显示国家/地区详细信息。我为两个国家创建了简单的数据库并使用php.now连接mysql如何使用jquery连接ajax中的php数据库?



简单的数据库:



'1','加拿大','北美','无','Giovanni Facciponte','已批准'





我的php数据库代码:





$ host =localhost;

$ port = 3306;

$ user =root;

$ password =;

$ dbname =mydatabase ;





$ country = $ _ POST ['country'];



$ con = new mysqli($ host,$ user,$ password,$ dbname,$ port,$ socket)

或die('无法连接到数据库服务器'.mysqli_connect_error() );



// $ con> close();



$ query =SELECT countryId,country,pdogcoregion,comments,ccl,category

FROM countrydetails

WHERE coun try ='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();

}



?>







我的脚本代码:





jQuery.noConflict();

jQuery(function(){

var $ = jQuery;

$('#focus-single ')。click(function(){

$('#map1')。vectorMap('set','focus',{region:'AU',animate:true});

});

$('#focus-multiple')。click(function(){

$('#map1')。vectorMap (记者et','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,

比例:1,

animate:true

},

系列:{

地区:[{

规模:['#688FA0'],

normalizeFunction:'polynomial',

值:{

onRegionClick:函数(事件,代码){

var map = $('#map1')。vectorMap('get','mapObject');

var name = map。 getRegionName(code);



$(document).ready(function(){

$ .ajax({

类型:GET,

contentType:'application / x-www-form-urlencoded',

url:'database.php',

数据:{country:'canada'},

dataType:text,

成功:函数(数据){

提醒(数据);

}

});

});





我的代码。我不知道我错在哪里?请问任何人发现我的代码错误?

解决方案

host =localhost;


port = 3306;


user =root;

I have created Map in Jvector map.its working. i did many customization.Now i want display country details from database. i created simple database for two country and connect mysql using php.now how to connect php database in ajax using jquery?

simple database:

'1', 'canada', 'North America', 'None', 'Giovanni Facciponte', 'Approved'


My php database code:


$host = "localhost";
$port = 3306;
$user = "root";
$password = "";
$dbname = "mydatabase";


$country=$_POST['country'];

$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();
}

?>



My script code:


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);

$(document ).ready(function() {
$.ajax({
type: "GET",
contentType: 'application/x-www-form-urlencoded',
url: 'database.php',
data: {country: 'canada'},
dataType: "text",
success: function(data){
alert(data);
}
});
});


its my code .i don't know where i did mistake ?please any one find my code mistake ?

解决方案

host = "localhost";


port = 3306;


user = "root";


这篇关于如何调用ajax php数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆