简体   繁体   English

选择下拉菜单后,如何通过sql数据库中的数据弹出jquery叠加层,如何发布信息?

[英]How do I POST when a dropdown is selected then popup a jquery overlay filed with data from a sql database?

I'm trying to create a jquery overlay displaying results from a sql database. 我正在尝试创建一个jQuery叠加,以显示来自SQL数据库的结果。 The results come from a select statement with php that was populated from the information received from an html select dropdown. 结果来自带有php的select语句,该语句是从html select下拉列表中接收的信息填充的。 Once the user has confirmed they've read, I want to update the database to reflect this and allow for the user to continue completing the original form. 用户确认已阅读后,我想更新数据库以反映此情况,并允许用户继续填写原始表格。

I can't figure out how to submit the original form, then pop up the overlay, submit the form on the overlay, but keep the original page allowing it to be completed. 我不知道如何提交原始表单,然后弹出叠加层,在叠加层上提交表单,但是保留原始页面以使其完成。

So this: 所以这:

    <form action="myformpage.php" method="post" id="myform">
     <select id="username" onchange="this.form.submit()">
      <option value='01'>User 1</option>
      <option value='02'>User 2</option>
     </select>

     <select id="location">
      <option value='north'>North</option>
      <option value='south'>South</option>
     </select>
    <input id="subbut" type="submit" value="SUBMIT" style="display: none;" />   
    </form>

jquery: jQuery的:

    <script type="text/javascript">
    $(document).ready(function () {
      $("#popup").overlay();
      $("#confirm").click(function() {
        $("#popup").overlay().close();
    var dataString = 'confirmread=Y';

  $.ajax({
  type: "POST",
  url: "read_message.php?",
  data: dataString,
  success: function() {
    $('#location').show();
    }
  });
      });
    </script>

Oddly the submit button never works when style is set to none. 奇怪的是,将样式设置为无时,提交按钮将永远无法使用。 (Side question: Is this because it was never visible to the browser at load?) (旁问:这是因为浏览器在加载时从不可见吗?)

You'll want to do an ajax post and generate the popup (probably via jQuery UI) with a successful post: 您将要进行ajax发布,并通过成功发布来生成弹出窗口(可能通过jQuery UI):

html: 的HTML:

 <select id="username">
  <option value='01'>User 1</option>
  <option value='02'>User 2</option>
 </select>

jquery: jQuery的:

$("#username").change( function() { 
    $.post( "myformpage.php", {username: $(this).val()}, function( data ) {
      // Create popup here

    });
});

your "myformpage.php" can take care of the database stuff and return whatever you want in your popup. 您的“ myformpage.php”可以处理数据库内容,并在弹出窗口中返回您想要的任何内容。

You don't even have to check for it if you want to do it like this. 如果要这样做,您甚至不必检查它。

        <?php 

//your connection to db goes here //您与数据库的连接在这里

          $message = "SELECT `message` FROM......";
          $test="true"
      ?>
      <script type="text/javascript">
       function checkit()
         {
           alert("<?php $message; ?>");
         }
      </script>
    <?php

2 options !!! 2个选择!

  1. using a redirect 使用重定向

      ?> <script> window.location.href="your page.php"; </script> 
  2. using css to hide & show 使用CSS隐藏和显示

      $var="display:none;"; if($test=="true") { $var=""; } ?> 

    HTML 的HTML

      <div style="<?php echo $var; ?>" name="original form" > your original form goes here </div> 

You need ajax for this, is easy with jQuery. 为此,您需要ajax,使用jQuery很容易。

with jQuery you need to do something like this: 使用jQuery,您需要执行以下操作:

<script>

$(function(){

     $("#username").change(function(){

            $.post("myformpage.php",{ value : $(this).val(), function(data){
                 alert(data);
            });
      });
});

</script>

You can't style the default alert, you need to make your own dialog or use a library that can do that, like jQuery ui. 您无法设置默认警报的样式,需要创建自己的对话框或使用可以执行此操作的库,例如jQuery ui。

EDIT 编辑

Yes IE have problems when you submit a form from javascript without a submit button but i recommend you to dont use that way to submit because this will do a postback that you dont need. 是的,当您从没有提交按钮的javascript提交表单时,IE会出现问题,但是我建议您不要使用这种方式提交,因为这将执行您不需要的回发。

Try something like this: 尝试这样的事情:

<script>
$(function(){

    $("#username").change(function(){

          $.post("retrievedata.php",{ username : $(this).val() },function(data){
                $("#popup").html(data);
                $("#popup").overlay();
          });

    });

    $("#confirm").click(function() {

        $("#popup").overlay().close();

        var dataString = 'Y';

        $.post("read_message.php",{confirmread:dataString},function(){
             $('#location').show();
        });

    });

});
<script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从选定的ajax下拉PHP插入数据 - How do I insert data from selected ajax dropdown PHP 如何通过视图中的javascript将选定的下拉项作为参数传递来调用发布动作响应 - How do I call a post actionresponse passing the selected dropdown item as a parameter from javascript within a view 如何使用从Select2下拉列表中选择的选项来触发jQuery? - How do I fire a jQuery with an option selected from a Select2 dropdown? 当从下拉菜单中选择选项时,如何使用jQuery将所选选项隐藏到另一个下拉菜单中 - When selected option from dropdown then how to hide that selected option into another dropdown using jQuery Angular JS-如何停止从多个表中重复相同的选定下拉数据 - Angular JS - How do I stop repeating same selected dropdown data from multiple table 在模式中编辑表单时,如何从依赖下拉列表中获取先前选择的选项? - When editing a form in a modal, how do I get the previously selected option from a dependent dropdown? 从下拉菜单中选择银行时,如何回显值(价格)? - How do I echo a value (a price) when a bank is selected from a dropdown menu? 从下拉列表中选择路径元素的值时,如何更改其颜色 - How do I change color of path element when its value is selected from dropdown 如何创建一个下拉列表,当选中该下拉列表时会更新一个输入字段? - How do I create a dropdown that when selected updates an input field? 选择下拉列表中的值时,如何完成自动填充? - How to do autocomplete when a value from dropdown is selected?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM