简体   繁体   English

如何知道何时使用 php 取消消息

[英]How to know when a message has been dismissed with php

I am adding announcements into my app which is basically a personal message to users.我正在向我的应用程序中添加公告,这基本上是给用户的个人信息。 They recieve the message then if they dismissed it I want to stop showing that specific again.他们收到消息然后如果他们驳回它我想停止再次显示该特定内容。

this is my php这是我的 php

  <?     $the_ID = $res_announcement->formal_announcement_id;  ?>

 <form action method="POST">


<div class="fade in pi-alert-warning pi-no-margin-bottom hide_msg_announcement">
      <div class="pi-section pi-row-sm hide_msg_announcement">
        <p class="pi-weight-600 pi-no-margin-bottom hide_msg_announcement">
            <i class="fa fa-exclamation-triangle pi-text-orange yellow blink_me" aria-hidden="true"></i>
            <span class="pi-text-dark"><?= $content_body ?></span>
            <?= $url_setup_pm ?>.
        </p>
  <div class=" pull-right checkbox checkbox-inline" style="margin-top: -16px;">
  <input type="checkbox" class="hide_msg_announcement" name="hide_msg" id="hide_msg_announcement" value="yes">
  <label class="pi-smaller-text pi-text-grey" for="hide_msg_announcement">dismiss</label>
    </div>
  </div>
</div>
</form> 

then I am hiding it with Jquery but i dont know how to store this specific messages ID or how get it from anywhere.然后我用 Jquery 隐藏它,但我不知道如何存储这个特定的消息 ID 或如何从任何地方获取它。 I tried passing php variables but always gets null.我尝试传递 php 变量,但总是为空。 I need a way to store the messages ID so I know not to display that message again to the user我需要一种存储消息 ID 的方法,以便我知道不会再次向用户显示该消息

 jQuery('body').on('change', '.hide_msg_announcement', function(e) {
    jQuery(".hide_msg_announcement").hide();
    if($(this).is(":checked")) {            
        $.ajax({
            url: 'on_off.php',
            dataType:'json',
            async:true,
            type: 'POST',
            data: { strID:$(this)},
            error: function(jqXHR, textStatus, errorThrown){
        }
        });
    }
});

Put $the_ID in the HTML so that jQuery can access it.$the_ID放在 HTML 中,以便 jQuery 可以访问它。 You can use a data- attribute for this.您可以为此使用data-属性。

<input type="checkbox" class="hide_msg_announcement" name="hide_msg" id="hide_msg_announcement" data-msg="<?php echo $the_ID; ?>" value="yes">

Then jQUery can use:然后jQUEry可以使用:

data: {strID: $(this).data("msg");},

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM