我试图从数据库中获取数据,但是我不明白为什么我没有得到任何输出。我使用jQuery/AJAX:
$(document).ready(function(){
$('#banktransfer_blz').blur( function(){
send_blz( $(this).val() );
} );
} );
function send_blz(str){
$.post( "get_swift.php",
{ sendBLZ: str },
function(data){
$('#banktransfer_bic').val( data.return_bic ).html();
},
"json");
}
下面是get_swift.php:
if (isset($_POST['sendBLZ'])){
$value = $_POST['sendBLZ'];
}
$test = "test";
$swift = xtc_db_query("SELECT customers_id FROM customers WHERE customers_cid ='20002'");
echo json_encode( array( "return_bic" => $swift) );
我连接到数据库了。
发布于 2014-01-30 11:24:23
尝试一下,您需要使用xtc_db_fetch_array
从表中获取customers_id
在get_swift.php中:
$swift = xtc_db_query("SELECT customers_id FROM customers WHERE customers_cid ='20002'");
$row = xtc_db_fetch_array($swift);
echo json_encode( array( "return_bic" => $row['customers_id']) );
另外,
$('#banktransfer_bic').val( data.return_bic );
而不是
$('#banktransfer_bic').val( data.return_bic ).html();
发布于 2014-01-30 11:24:33
尝试使用浏览器的开发工具并检查XHR请求。如果没有问题,请确保要从哪里获取数据的页面分别连接到数据库。您可以通过直接从浏览器的URL访问此页面来检查这一点,并且输出应该是您通过ajax想要的。
同样在ajax代码中,请尝试更改
$('#banktransfer_bic').val( data.return_bic ).html();
至
$('#banktransfer_bic').html( data.return_bic );
发布于 2014-01-30 11:24:37
我假设您在直接调用php文件时得到了所需的响应。
您正在通过执行#banktransfer_bic
来重置$('#banktransfer_bic').html();
html。
尝试使用:$('#banktransfer_bic').html(data.return_bic);
代替
https://stackoverflow.com/questions/21454965
复制相似问题