doudang1890 2014-12-19 07:52
浏览 47
已采纳

通过JQuery,php,mysql收到的数据不起作用

enter image description here

On entering the customer name in textbox it searches for customer info. I have generated successfully using JQuery by passing the entire table through Json variable, as I dont want any page refresh. Now I want to select the customer id generated from mysql db (php) through radio button, but the radio button event is not working. For testing purpose I have put a static table having the same radio button properties in that particular div(place for dynamic record generation using JQuery) and working fine. Hence I found that the data received through JQuery got some problem. Hope I am clear. Please find a way. Thanks in advance.

below is the code

abc.php

<input type="text" placeholder="full name" id="fullName" name="fullName" class="txt" style="width: 250px" />&ensp;
<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"].'&ensp;<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);
}
  • 写回答

2条回答 默认 最新

  • dongshai1944 2014-12-19 07:57
    关注

    Maybe You should'nt bind the event properly for the dynamic elements in the DOM.

    Try Like this

    $('body').on('change','.radiobuttonClassorID',function(){
        //actions
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝