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);
        });    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退