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 远程安装一下vasp
  • ¥15 自己做的代码上传图片时,报错
  • ¥15 Lingo线性规划模型怎么搭建
  • ¥15 关于#python#的问题,请各位专家解答!区间型正向化
  • ¥15 unity从3D升级到urp管线,打包ab包后,材质全部变紫色
  • ¥50 comsol温度场仿真无法模拟微米级激光光斑
  • ¥15 上传图片时提交的存储类型
  • ¥15 VB.NET如何绘制倾斜的椭圆
  • ¥15 arbotix没有/cmd_vel话题
  • ¥15 odoo17的分包重新供应路线如何设置?可从销售订单中实时直接触发采购订单或相关单据