weixin_33690367 2014-05-17 15:02 采纳率: 0%
浏览 44

使用AJAX发布输入OnChange

Just some AJAX troubleshooting.

Context: Building a large table with input that should post as soon as their filled out. Thought the onchange trigger would work best.

Issue: I can't seem to get the javascript to pass the value of the input over to the .php sheet.


header.php

$(document).ready(function(){
  $(".matchedit").onchange(function postinput(){ // Problem 1: change(
    var matchvalue = $(this).value; // Problem 2: $(this).val();
    $.ajax
        ({ 
            url: 'matchedit-data.php',
            data: {matchvalue: matchvalue},
            type: 'post'
        });
  });
}); 

page.php

<tr>
  <td>
    <input name="grp1" type="text" class="matchedit" onchange="postinput()">
  </td>
</tr>

matchedit-data.php

$entry = $_POST['matchvalue'];
$conn->query("UPDATE matches SET grp = '$entry' WHERE mid = 'm1'");

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • 笑故挽风 2014-05-17 15:14
    关注

    For reading the value of a jQuery wrapped input .val() method should be used, value here returns an undefined value. Also you should either use .on('change') or change() method, jQuery object doesn't have onchange method.

    $(document).ready(function(){
        $(".matchedit").on('change', function postinput(){
            var matchvalue = $(this).val(); // this.value
            $.ajax({ 
                url: 'matchedit-data.php',
                data: { matchvalue: matchvalue },
                type: 'post'
            }).done(function(responseData) {
                console.log('Done: ', responseData);
            }).fail(function() {
                console.log('Failed');
            });
        });
    }); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器