【发布时间】:2015-02-18 03:19:53
【问题描述】:
在文本框中输入客户姓名后,它会搜索客户信息。我通过 Json 变量传递整个表,使用 JQuery 成功生成,因为我不想要任何页面刷新。现在我想通过单选按钮选择从 mysql db (php) 生成的客户 ID,但单选按钮事件不起作用。出于测试目的,我在该特定 div 中放置了一个具有相同单选按钮属性的静态表(使用 JQuery 生成动态记录的位置)并且工作正常。因此我发现通过 JQuery 接收到的数据有问题。希望我清楚。请想办法。提前致谢。
下面是代码
abc.php
<input type="text" placeholder="full name" id="fullName" name="fullName" class="txt" style="width: 250px" /> 
<input type="button" id="btSelect" value="Select" class="button-crystal" />
<div id="disp"></div>
script.js
$('#btSelect').click(function () {
var form_data = {
genCustDetails: $('#fullName').val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: "xyz.php",
data: form_data,
dataType: "json",
success: function (response)
{
$('#disp').html(response);
}
});
return false;
});
xyz.php
if (isset($_POST['genCustDetails'])) {
$out="";
$result = mysql_query("select * from dbcustdetails where name like '$_POST[genCustDetails]%'");
while ($row = mysql_fetch_assoc($result)) {
$out.='
<table style="background-color:#eee; margin-bottom:5px;">
<tr>
<th class="td3">Customer ID</th>
<td class="td4">
'.$row["custID"].' <input type="radio" id="cust_ID" name="cust_ID" value="'.$row["custID"].'" />
</td>
</tr>
<tr>
<th class="td3">Name</th>
<td class="td4">'.$row["name"].'</td>
</tr>
<tr>
<th class="td3">Phone No.</th>
<td class="td4">'.$row["phno"].'</td>
</tr>
<tr>
<th class="td3">Email</th>
<td class="td4">'.$row["email"].'</td>
</tr>
<tr>
<td colspan="2" style="padding:0;">
<b>Address</b><br/>'.$row["addr"].'
</td>
</tr>
</table>';
}
echo json_encode($out);
}
【问题讨论】:
-
您可能必须使用 (on)[api.jquery.com/on/] 或其他方式将您的广播事件绑定到 ajax 响应