【问题标题】:Php post form with onkeyup function [closed]具有 onkeyup 功能的 PHP 发布表单 [关闭]
【发布时间】:2014-02-14 13:17:16
【问题描述】:

我的表格:

  <tfoot>
      <form method="post" action="kategoriler.php">
    <tr>
     <th>Select</th>
     <th><input type="text" name="id" id="id" class="form-control" style="width:80px;" placeholder="#"></th>
     <th>Image</th>
     <th><input type="text" name="name" id="name"  class="form-control" style="width:120px;" placeholder="Name"></th>
     <th>Order</th>
     <th><input type="text" name="Visibility" id="Visibility" class="form-control" style="width:120px;" placeholder="Visibility"></th>
     <th>Date</th>
     <th>Edit</th>
    </tr>
     </form>
  </tfoot>

我想用 json 和 onkeyup 函数发布这个值,我该如何发送这个表单值?

【问题讨论】:

标签: php jquery json


【解决方案1】:

这可以在表单中的所有输入类型上添加 keyup 功能

$('form input:text').keyup(function(){
      var data = $("form").serialize();
      $.ajax({
        url: 'kategoriler.php',
        data: data,
        dataType:'json',
        type:'POST',
        async:false,
        success: function(data) {
          alert('submitted');
        }
});

如果您想在特定输入类型上添加 keyup,则只需替换

$('form input:text').keyup(function(){

$('#id').keyup(function(){

【讨论】:

  • 我怎样才能在 kategoriler.php 上获得这个值,例如我发送了名字,但我不能在其他页面上取这个名字
  • 使用 $_POST...like $all_input_values = $_POST 然后 $all_input_values['id'] 这将为您获取 id 值..对其他人使用相同
【解决方案2】:

为此使用 jQuery ajax:

$(document).keydown(function(e) {
    $.ajax({
              type: "POST",
              dataType: "json",
              url: "kategoriler.php",
              data: {name: $('#name').val() //ETC...},
              success: function (html) {
                 alert('ok');
              }
         });
    });

【讨论】:

  • onkeyup op 想提交这个事件的表单。
  • 这个方法在我按下任何按钮时都会起作用?
【解决方案3】:

你可以这样做。前提是您要在任何键盘上提交表单

 //trigger form submit
 $(document).keyup(function(){
     $("form").submit();
 });

 //Do what you whant with your form
 $("form").submit(function(){
     //Do something eg. ajax call
      $.ajax({
           type: "POST",
           dataType: "json",
           url: "kategoriler.php",
           data: {name: $('#name').val() //ETC...},
           success: function (html) {
              alert('ok');
           }
      });
 });

【讨论】:

  • 当我按下任何按钮时,我没有想要处理的提交按钮?
  • 好的。但是当用户在您的文本字段中输入内容时,这不是问题吗?这意味着表单会为每个字符提交。在我看来,使用 onChange() 会更方便。
  • 我怎样才能得到这个值:)
  • 使用 change() 而不是 keyup() 触发提交。您可以按照其他帖子中描述的相同方式获取值
猜你喜欢
  • 1970-01-01
  • 2016-03-31
  • 1970-01-01
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
  • 2020-03-04
  • 1970-01-01
  • 2013-01-02
相关资源
最近更新 更多