doukuo9116 2015-01-17 06:49 采纳率: 100%
浏览 29
已采纳

jquery onclick只用一个输入从php文件中获取数据

Here is the HTML (This form may use more than twice) :-(

<div class="abc">
  <div class="xyz">
    <input type="text" name="pqr" />
    <div class="clickMe">click button</div>
    <div class="showContent"></div>
  </div>
  <div class="somethingelse">some other insignificent input or something else.</div>
</div>

Here is the jQuery:

$('.clickMe').on('click', function(e){

    $.post("getdata.php", $(this).closest('.abc').children('.xyz').children('input[name="pqr"]').serialize(),  function(response) {
        $(this).closest('.abc').children('.xyz').children('.showContent').html(response);
    });

});

i need only to check data of input(pqr) with my database?
any idea, how can i it and what is wrong on my code!
Advance thanks.

  • 写回答

1条回答 默认 最新

  • dstew32424 2015-01-17 07:00
    关注

    The scope of this inside of the post is not the same as outside

    $('.clickMe').on('click', function(e){
        e.preventDefault();
        var xyz = $(this).closest('.abc').children('.xyz');
        $.post("getdata.php", xyz.children('input[name="pqr"]').serialize(),  function(response) {
            xyz.children('.showContent').html(response);
        });    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题