doudang1890
doudang1890
2014-12-19 07:52

通过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 dongshai1944 7年前

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

    Try Like this

    $('body').on('change','.radiobuttonClassorID',function(){
        //actions
    });
    
    点赞 评论 复制链接分享
  • dounao1856 dounao1856 7年前

    that is because your newly generated radio button is not having any event handler assigned to it.

    you have to assign an event handler after the ajax call (on ajax success). something like

    $('input[type="radio"]').unbind('click').click(function(){
        //Your handler code
    })
    
    点赞 评论 复制链接分享

相关推荐