在单选按钮上显示div中的数据单击ajax

时间:2013-08-29 19:15:53

标签: php jquery ajax

我希望用户在ajax调用中显示所选数据。

场景是我有两个单选按钮,当用户点击其中任何一个时,它应该在响应div的右侧显示相应的数据。

HTML:

<form id="package-call" method="post" accept-charset="utf-8">
    <div class='pakges'>
        <div class="sub-pakge">
            <div class="sub-pakge-content">
                <span class="content-title">North America</span><br>
                <span class="content-title">Basic</span>
                <div class="content-time">150 Minutes</div>
                <span class="content-price">Rs.500</span>
                <div class="pakges-radio"><input type="radio" name="package" id="package" >    </div>
            </div>
        </div>
        <div class="sub-pakges">
            <div class="sub-pakges-content">
                <span class="content-title">North America</span><br>
                <span class="content-title">Max</span>
                <div class="content-time">400 Minutes</div>
                <span class="content-price">Rs.200</span>
                <div class="pakges-radio"><input type="radio" name="package" id="package">   </div>

            </div>
        </div>
    </div>
</form>

AJAX:

$("#package").click(function(e){ 

    $.ajax( {
        type: "POST",
        url: "package _selection.php",
        data: $('#package_call').serialize(),
        success: function( response ) {}
    });

});

这是我希望显示我的回复的div:

<div class="form-results">
    <div class="rslt-content-main">
        <div class="rslt-content">Selected Pakages / Bolts</div>
        <div id="package_response"></div>
    </div>
</div>

这些是我希望通过包_selection.php进行ajax调用并希望分别显示的结果div

<div class="radio_one_rslt">
    <div>voice:</div><br />
    <div>IDD Asia - Rs 200</div>
</div>

<div class="radio_two_rslt">
    <div>voice:</div><br />
    <div>IDD Asia - Rs 500</div>
</div>

1 个答案:

答案 0 :(得分:3)

要收听单选按钮,请使用&#39;更改&#39;事件

$("#package").on('change', function(e){ 

然后,假设您的回复是您想要追加的HTML,请将其附加到您的成功回调

$.ajax( {
  type: "POST",
  url: "package _selection.php",
  data: $('#package_call').serialize(),
  success: function( response ) {
    $('#package_response').append(response);
  }
});

博客文章供参考:http://blog.stephenborg.com/?p=37