Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与用户输入接口作为服务器端php和客户端更新的触发器?_Php_Javascript_Programming Languages_Client Side_Server Side - Fatal编程技术网

与用户输入接口作为服务器端php和客户端更新的触发器?

与用户输入接口作为服务器端php和客户端更新的触发器?,php,javascript,programming-languages,client-side,server-side,Php,Javascript,Programming Languages,Client Side,Server Side,我很难用措辞表达我的问题的标题。基本上,问题是: 我有一个由5个可视行组成的界面,它们只因输入和名称而不同 每行中有2个选择框/列表,我希望第二个选择列表填充7个不同数组中的一个(通过查询数据库生成),具体取决于用户在第一个选择框中所做的选择(第一个框仅影响部分查询的顺序) 如何在用户在选择框中进行选择后立即执行此操作? 这意味着用户无需按下任何其他提交按钮。我希望大部分代码处理都是服务器端的,但输出立即在客户端可见。如果每次用户更改一个选择框时整个页面都会刷新,那就太糟糕了,因为他需要在所有5

我很难用措辞表达我的问题的标题。基本上,问题是:

我有一个由5个可视行组成的界面,它们只因输入和名称而不同

每行中有2个选择框/列表,我希望第二个选择列表填充7个不同数组中的一个(通过查询数据库生成),具体取决于用户在第一个选择框中所做的选择(第一个框仅影响部分查询的顺序)

如何在用户在选择框中进行选择后立即执行此操作? 这意味着用户无需按下任何其他提交按钮。我希望大部分代码处理都是服务器端的,但输出立即在客户端可见。如果每次用户更改一个选择框时整个页面都会刷新,那就太糟糕了,因为他需要在所有5个选项中选择一些内容


我需要将我的php与一些javascript结合起来才能实现这一点吗?如果是这样的话,我在寻找什么样的代码?

如果您使用jquery,这可能非常简单

/* pick up the first select box changing */
$(".select_box_class").change(function() {

  /* show some loading indicator */
  show_loading_indicator();

  /* fire off a ajax call to the server which could return the html for the next select box or the data to build up the html in the client */
  $.post('/path/to/server.php',{selection:$(this).val()}, function(newSelect) {
      /* here you can update/create you next select box */
      $("#select_box2_placeholder").html(newSelect);

      turn_off_loading();
  });

});

如果您使用的是jquery,那么这可能非常简单

/* pick up the first select box changing */
$(".select_box_class").change(function() {

  /* show some loading indicator */
  show_loading_indicator();

  /* fire off a ajax call to the server which could return the html for the next select box or the data to build up the html in the client */
  $.post('/path/to/server.php',{selection:$(this).val()}, function(newSelect) {
      /* here you can update/create you next select box */
      $("#select_box2_placeholder").html(newSelect);

      turn_off_loading();
  });

});

我相信这就是所谓的
层叠选择框
链式选择框
。好极了,既然我知道了这个名字,我就可以轻松地用谷歌搜索教程了!泰!:)我相信这就是所谓的
层叠选择框
链式选择框
。好极了,既然我知道了这个名字,我就可以轻松地用谷歌搜索教程了!泰!:)嗯,我还不太熟悉javascript。但我知道这很容易学习,而且可能是解决我在这里面临的基于客户的问题的最好方法。是否有一些书/教程介绍了如何使用php和javascript来实现我的目标?不要忘记:文档应该完全加载,以便能够使用这些元素<代码>jQuery(document).ready(function(){jQuery(#element1”).change(function(){jQuery.post('selectmaker.php',{selection:jQuery(#element1”).val()},function(newSelect){jQuery(“select#element2”).html(newSelect);})嗯,我还不太熟悉javascript。但我知道这很容易学习,而且可能是解决我在这里面临的基于客户的问题的最好方法。是否有一些书/教程介绍了如何使用php和javascript来实现我的目标?不要忘记:文档应该完全加载,以便能够使用这些元素<代码>jQuery(document).ready(function(){jQuery(#element1”).change(function(){jQuery.post('selectmaker.php',{selection:jQuery(#element1”).val()},function(newSelect){jQuery(“select#element2”).html(newSelect);})