使用AJAX发布我发送数据和在其他页面上,根据此数据,我通过查询检索mysql数据库的两个不同列值。我需要通过AJAX取回这两个不同的值,并在两个不同的输入中显示。
var mus_barkod = document.getElementById('mus_barkod').value;
var dataString = "mus_barkod="+mus_barkod;
$.ajax({
type: "POST",
url: "musteri_indir.php",
data: dataString,
success: function(result){
$("#indirim").val(result.mus_indirim);
$("#mus_isim").val(result.mus_isim);
这是AJAX的一部分,在获取数据的(OLD)查询之下:
$mus_barkod = $_REQUEST['mus_barkod'];
$mus_cek = mysql_query("SELECT * FROM musteriler WHERE mus_barkod =
'".$mus_barkod."' AND sub_id = '".$per_sube."' ");
while ($mus_al=mysql_fetch_array($mus_cek)){
$mus_isim = $mus_al['mus_isim'];
$mus_indirim= $mus_al['mus_indirim'];
}
$mus_isim1 = 'Kayıtlı Müşteri Değil';
$mus_indirim1 = '0.00';
if($mus_barkod == '10' || $mus_barkod == '100090'|| $mus_barkod ==
'100237')
{
echo
$mus_indirim,$mus_isim;
}else{
echo
$mus_indirim1,$mus_isim1;
}
那么我如何能够单独回到mus_indirim和mus_isim并在不同的输入中显示? 注意:不要介意mysql_,这是一个旧系统。 PDO永远:)
答案 0 :(得分:0)
通过更仔细地检查我的代码来修复它。以下是那些需要相同解决方案的结果:
var mus_barkod = document.getElementById('mus_barkod').value;
var dataString = "mus_barkod="+mus_barkod;
$.ajax({
type: "POST",
url: "musteri_indir.php",
data: dataString,
dataType: "json", => the little thing i forgot to write :)
success: function(result){
$("#indirim").val(result.mus_indirim);
$("#mus_isim").val(result.mus_isim);
旧PHP:
$mus_barkod = $_REQUEST['mus_barkod'];
$mus_cek = mysql_query("SELECT * FROM musteriler WHERE mus_barkod =
'".$mus_barkod."' AND sub_id = '".$per_sube."' ");
while ($mus_al=mysql_fetch_array($mus_cek)){
$mus_isim = $mus_al['mus_isim'];
$mus_indirim= $mus_al['mus_indirim'];
}
if($mus_barkod == '10' || $mus_barkod == '100090'|| $mus_barkod ==
'100237')
{
echo json_encode(array("mus_indirim" => $mus_indirim, "mus_isim" =>
$mus_isim));
}else{
echo json_encode(array("mus_indirim" => '0.00', "mus_isim" => 'Kayıtlı
Müşteri Değil'));
}