douzhen1234 2016-01-28 21:37
浏览 49

不会做功能,只刷新

I have php page that include function doesn't work when click on button, it's only when click do refresh the page

    <!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){

            });
            function sendPushNotification(id){
                var data = $('form#'+id).serialize();
                $('form#'+id).unbind('submit');                
                $.ajax({
                    url: "send_message.php",
                    type: 'POST',
                    data: data,
                    beforeSend: function() {

                    },
                    success: function(data, textStatus, xhr) {
                          $('.txt_message').val("");
                    },
                    error: function(xhr, textStatus, errorThrown) {

                    }
                });
                return false;
            }
        </script>
        <style type="text/css">
            .container{
                width: 950px;
                margin: 0 auto;
                padding: 0;
            }
            h1{
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 24px;
                color: #777;

            }
            div.clear{
                clear: both;
            }
            ul.devices{
                margin: 0;
                padding: 0;
            }
            ul.devices li{
                float: right;
                list-style: none;
                border: 1px solid #dedede;
                padding: 10px;
                margin: 0 15px 25px 0;
                border-radius: 3px;
                -webkit-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
                -moz-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
                box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                color: #555;
            }
            ul.devices li label, ul.devices li span{
                font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
                font-size: 12px;
                font-style: normal;
                font-variant: normal;
                font-weight: bold;
                color: #393939;
                display: block;
                float: right;
            }
            ul.devices li label{
                height: 25px;
                width: 50px;                
            }
            ul.devices li textarea{
                float: right;
                resize: none;
            }
            ul.devices li .send_btn{
                background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0096FF), to(#005DFF));
                background: -webkit-linear-gradient(0% 0%, 0% 100%, from(#0096FF), to(#005DFF));
                background: -moz-linear-gradient(center top, #0096FF, #005DFF);
                background: linear-gradient(#0096FF, #005DFF);
                text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
                border-radius: 3px;
                color: #fff;
            }
        </style>
      <style>
      .ticketnumber {position:relative; right:5px}
      </style>

    </head>
    <body>
        <?php
        include_once 'db_functions.php';
        $db = new DB_Functions();
        $users = $db->getAllUsers();
        if ($users != false)
            $no_of_users = mysql_num_rows($users);
        else
            $no_of_users = 0;
        ?>


        <div class="container" align="right">

            <h1><?php echo $no_of_users; ?> :عدد الأجهزة المسجلة </h1>
            <hr/>

            <ul class="devices">
                <?php
                if ($no_of_users > 0) {
                    ?>
                    <?php
                    while ($row = mysql_fetch_array($users)) {
                        ?>

                        <li>
                            <form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit="return sendPushNotification('<?php echo $row["id"] ?>')">


                                <label dir="rtl">الإسم: </label> <span><?php echo $row["name"] ?></span>
                                <div class="clear"></div>
                                <label dir="rtl" >الإيميل:</label> <span><?php echo $row["email"] ?></span>
                                <div class="clear"></div>
                                <p4>
                                 <label dir="rtl" >رقم التذكرة: </label> <div class="ticketnumber"><span><?php echo $row["ticketnumber"] ?></span> </div>
                                <div class="clear"></div>
                                </p4>
                                <div class="send_container">                                
                                    <textarea dir="rtl" rows="3" name="message" cols="25" class="txt_message" placeholder="اكتب الرسالة هنا"></textarea>
                                    <input type="hidden" name="regId" value="<?php echo $row["gcmregid"] ?>"/>
                                    <input type="submit" class="send_btn" value="إرسال" onclick=""/>
                                </div>
                            </form>

                        </li>

                    <?php }
                } else { ?> 

                    <li>


                                    لايوجد أجهزة مسجلة

                    </li>

                <?php } ?>
            </ul>
        </div>

    </body>
</html>

send_message.php

    <?php
if (isset($_GET["gcmregid"]) && isset($_GET["message"])) {
    $regId = $_GET["gcmrgid"];
    $message = $_GET["message"];

    include_once '/GCM.php';

    $gcm = new GCM();

    $registatoin_ids = array($regId);
    $message = array("message" => $message);

    $result = $gcm->send_notification($registatoin_ids, $message);

    echo $result;
}
?>

=========================================================================

  • 写回答

2条回答 默认 最新

  • dra8603 2016-01-28 21:40
    关注

    Spot the differences:

    <form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit[..snip...]
                                                       ^^^^^^
    
    if (isset($_GET["gcmregid"]) && isset($_GET["message"])) {
               ^^^^^                       ^^^^
    

    Plus, your html is broken... <p4>? Since when has there been different kinds of paragraph tags?

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退