jquery onclick 从只有一个输入的 PHP 文件中获取数据

jquery onclick get data from php file with only one input

本文关键字:文件 PHP 获取 数据 输入 onclick 有一个 jquery      更新时间:2023-09-26

这是 HTML (此表单可能使用两次以上) :-(

<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>

这是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);
    });
});

我只需要用我的数据库检查输入(PQR)的数据?
任何想法,我怎么能做到,我的代码出了什么问题!
提前感谢。

帖子内部的this范围与帖子外部不同

$('.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);
    });    
});