Javascript 韩元';t to do函数,仅刷新
我有一个php页面,当点击按钮时包含的函数不起作用,只有当点击刷新页面时才起作用Javascript 韩元';t to do函数,仅刷新,javascript,php,jquery,Javascript,Php,Jquery,我有一个php页面,当点击按钮时包含的函数不起作用,只有当点击刷新页面时才起作用 <!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="http://ajax
<!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>
$(文档).ready(函数(){
});
函数sendPushNotification(id){
var data=$('form#'+id).serialize();
$('form#'+id).unbind('submit');
$.ajax({
url:“send_message.php”,
键入:“POST”,
数据:数据,
beforeSend:function(){
},
成功:函数(数据、文本状态、xhr){
$('.txt_message').val(“”);
},
错误:函数(xhr、textStatus、errorshown){
}
});
返回false;
}
.集装箱{
宽度:950px;
保证金:0自动;
填充:0;
}
h1{
字体系列:“Helvetica Neue”,Helvetica,Arial,无衬线;
字体大小:24px;
颜色:#777;
}
分区清除{
明确:两者皆有;
}
保险设备{
保证金:0;
填充:0;
}
ul.li{
浮动:对;
列表样式:无;
边框:1px实心#dedede;
填充:10px;
边际:0 15px 25px 0;
边界半径:3px;
-webkit盒阴影:0 1px 5px rgba(0,0,0,0.35);
-moz盒阴影:0 1px 5px rgba(0,0,0,0.35);
盒影:0 1px 5px rgba(0,0,0,0.35);
字体系列:“Helvetica Neue”,Helvetica,Arial,无衬线;
颜色:#555;
}
ul设备li标签,ul设备li跨度{
字体系列:“Helvetica Neue”,Helvetica,Arial,无衬线;
字体大小:12px;
字体风格:普通;
字体变体:正常;
字体大小:粗体;
颜色:#393939;
显示:块;
浮动:对;
}
ul.li标签{
高度:25px;
宽度:50px;
}
ul.li文本区域{
浮动:对;
调整大小:无;
}
ul.devices li.send\u btn{
背景:-webkit梯度(线性,0%0%,0%100%,从(#0096FF)到(#005DFF));
背景:-webkit线性梯度(0%0%,0%100%,从(#0096FF)到(#005DFF));
背景:-莫兹线性梯度(中上,#0096FF,#005DFF);
背景:线性梯度(#0096FF,#005DFF);
文本阴影:0 1px 0 rgba(0,0,0,0.3);
边界半径:3px;
颜色:#fff;
}
.ticketnumber{位置:相对;右侧:5px}
:عدد الأجهزة المسجلة
-
找出差异:
<form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit[..snip...]
^^^^^^
if (isset($_GET["gcmregid"]) && isset($_GET["message"])) {
^^^^^ ^^^^
PHP函数中的echo
在使用ajax时不会向页面添加任何内容,它只是将数据返回到success
函数中的data
变量,您必须在该变量中找到如何处理它的方法。现在你什么都没做这就是为什么什么都没发生老板?有帮助吗?
<form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit[..snip...]
^^^^^^
if (isset($_GET["gcmregid"]) && isset($_GET["message"])) {
^^^^^ ^^^^
success: function(data, textStatus, xhr) {
$('.txt_message').val(data);
},