嘗試用了 ajax ,很有趣。應用在訂閱電子報上頭。
order html
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
</head>
<body>
<form class="form-inline" role="form" id="order_email" action="" name="order_email">
<input type="email" class="form-control" id="inputEmail" placeholder="輸入 email 訂閱電子報">
<a class="btn btn-default" value="訂閱" id="update" onclick="orderEmail();">訂閱</a>
</form>
<script type="text/javascript">
function orderEmail(){
myReg = /^.+@.+\..{2,3}$/
var email_data = $("#inputEmail").val();
if( !$("#inputEmail").val().match(myReg) ){
alert("E-mail 格式錯誤,請檢查重填,謝謝!");
$("#inputEmail").val('');
}else{
$.ajax({
url: 'member_order_email.php',
data: {email: email_data},
error: function(xhr) { },
success: function(response) { alert(response); }
});
}
};
</script>
</body>
</html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
</head>
<body>
<form class="form-inline" role="form" id="order_email" action="" name="order_email">
<input type="email" class="form-control" id="inputEmail" placeholder="輸入 email 訂閱電子報">
<a class="btn btn-default" value="訂閱" id="update" onclick="orderEmail();">訂閱</a>
</form>
<script type="text/javascript">
function orderEmail(){
myReg = /^.+@.+\..{2,3}$/
var email_data = $("#inputEmail").val();
if( !$("#inputEmail").val().match(myReg) ){
alert("E-mail 格式錯誤,請檢查重填,謝謝!");
$("#inputEmail").val('');
}else{
$.ajax({
url: 'member_order_email.php',
data: {email: email_data},
error: function(xhr) { },
success: function(response) { alert(response); }
});
}
};
</script>
</body>
</html>
member_order_email.php
當中處理訂閱的檢查與訂閱動作,傳回狀態。
就好惹~~
0 留言