0
昨天我設法讓我的數據從數據庫輸出並存儲到java數組中。然而,這是負載,現在該代碼將不會工作點擊。 所以我讀過關於Ajax和有此功能:從jquery運行php點擊,從php文件返回數組,調用另一個文件
var infArray = new Array();
var country;
$('#australia').click(function() {
//console.log("you clicked"+txt);
country = 'Australia';
$.ajax({
type: 'POST',
url: 'php/Maps.php',
data: {country: country},
success: function(data){
alert("success"+data); // this will hold your $result value
infArray = JSON.parse(data)
console.log('Return:' + data);
}
});
});
按照我的理解這打開包含函數的PHP文件,並允許您使用$ _ POST使用變量「國家」。
所以我的PHP文件看起來像這樣:
<?php
require '../classes/Mysql.php';
function get_Stockist(){ // if su = 0 then stockist if = 1 then member
$mysql = new Mysql();
$result = $mysql->getInfo($_POST['country']);
echo json_encode($result);
}
所以再次在我眼裏
,$結果被設置爲方法的結果:在Mysql.php :
function getinfo($country){
$rows = array();
$query = "SELECT Name,add1 FROM stockistsWorld WHERE Country = '". mysql_escape_string($country) ."' LIMIT 5";
//$query = "SELECT Name,add1 FROM stockistsUK LIMIT 10";
$result = mysqli_query($this->conn, $query);
/* numeric array */
while($row = mysqli_fetch_array($result, MYSQLI_NUM)){
$rows[] = $row;
}
return $rows;
}
然而在我的HTML結果爲空
我改成了我的資本,而只是刪除方法所以現在Maps.php看起來像' getInfo($ _ POST ['country']); \t \t fb('3',FirePHP :: TRACE); \t \t $ res = 1; \t \t fb('4',FirePHP :: TRACE); \t \t echo json_encode($ result); \t \t fb('5',FirePHP :: TRACE); \t \t'也安裝了FIREPHP好!我希望這是一個好的解決方案 –