Jquery 如何停止模式对话框上的重复入口
避免用户两次输入同一记录的最佳方法是什么。我的插件中有以下内容Jquery 如何停止模式对话框上的重复入口,jquery,wordpress,twitter-bootstrap,wordpress-theming,Jquery,Wordpress,Twitter Bootstrap,Wordpress Theming,避免用户两次输入同一记录的最佳方法是什么。我的插件中有以下内容 jQuery(document).ready(function(){ jQuery("#submit").click(function(){ var points = jQuery("#points]").val(); jQuery.ajax({ type: 'POST', url: MyAjax.ajaxurl, data: {"action": "updateRedeemPoin
jQuery(document).ready(function(){
jQuery("#submit").click(function(){
var points = jQuery("#points]").val();
jQuery.ajax({
type: 'POST',
url: MyAjax.ajaxurl,
data: {"action": "updateRedeemPoints", "points":points},
success: function(data){
alert(data);
}
});
});
我的函数只是发布到我想停止它插入数据库两次,但它应该生成一个比javascript默认值更友好的消息框,或者可以使用引导通知
wp_localize_script( 'gogreen', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));
function updateRedeemPoints(){
$userId = get_current_user_id();
$mykey = 'player_id';
$single = true;
$playerId = get_user_meta( $userId, $mykey, $single );
$points=$_POST['points'];
global $wpdb;
$wpdb->insert(
'4hSIc_pods_player_ranking',
array(
'points_to_redeem' =>$points,
'player_id'=>$playerId,
'date_to_be_awarded' => current_time('mysql', 1),
'approved'=>'false'
));
$headers = "From: " . $form_data['name'] . " <" . $form_data['email'] . ">\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
wp_mail( 'davidbuckleyni.co.uk', 'test', 'test', $headers );
wp\u本地化脚本('gogreen','MyAjax',array('ajaxurl'=>admin\u url('admin ajax.php'));
函数updateRedeImpoints(){
$userId=get_current_user_id();
$mykey='player_id';
$single=true;
$playerId=get\u user\u meta($userId、$mykey、$single);
$points=$_POST['points'];
全球$wpdb;
$wpdb->插入(
“4hSIc_pods_player_排名”,
数组(
“积分兑换”=>$points,
'player_id'=>$playerId,
“授予日期”=>当前时间('mysql',1),
“已批准”=>“错误”
));
$headers=“From:”.$form\u data['name']。“\n”;
$headers.=“内容类型:文本/普通;字符集=UTF-8\n”;
$headers.=“内容传输编码:8位\n”;
wp_邮件('davidbuckleyni.co.uk','test','test',$headers);
顺便说一句,我使用的是一个引导模型,如果它有区别的话
echo "<div id='thanks' class='modal fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>";
echo "<h4 class='modal-title'>Redeem Points</h4>";
echo "</div>";
echo "<form class='form-horizontal' class='contact' name='redemmpointsForm' id='redemmpointsForm' >";
echo " <div class='form-group'>";
echo "<h3>You may only redeem the maxium points of : <?php echo $maxpoints;?></h3>";
echo "<input type='hidden' name='playerid' value='<?php echo $playerId;;?>' />";
echo "<input type='number' valuemax='<?php echo $maxpoints;?>' name='points' id='points' class='form-control' placeholder='How many points do you wish to redeem.' />";
echo "<label class='control-label col-md-4' for='Comments'>Comments?</label>";
echo "<input type='text' name='comments' />";
echo " </div>";
echo " <div class='form-group'>";
echo " <div class='col-md-6'>";
echo " <input type='button' class='btn btn-success' name='submit' id='submit' Text='Submit'>";
echo " <a href='#' class='btn' data-dismiss='modal'>Close</a>";
echo " </div>";
echo " </div>";
echo "</form>";
echo " </div>";
echo " </div>";
echo " </div>";
echo”“;
回声“;
回声“;
回声“;
回声“×”;
回显“兑换积分”;
回声“;
回声“;
回声“;
echo“您只能兑换的最大积分:”;
echo“您可以在AJAX请求之前禁用submit按钮,并在收到来自服务器的成功响应时向用户显示消息
因为您已经在使用引导,所以可以使用引导警报来显示友好的成功消息
例如,包括以下内容
<div class="alert alert-success alert-dismissible" id="points-success" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Success!</strong> Great! Your points have been redeemed.
</div>
在Ajax错误回调中,您应该再次启用该按钮,并向用户显示错误消息(例如,带有警报错误).我想知道的是,尽管我真的很想使用通知,或者它们不是引导中的默认通知,但你会有一个css示例来隐藏表单。我真的不明白你的意思。你可以将代码片段放在表单的某个地方,例如,按钮下面。然后在css中,你可以说#points success{显示:无;},这样警报将在默认情况下隐藏,javascript片段将在Ajax调用成功时显示警报。请在新的屏幕截图中看一看,它工作了,但将其放在代码的末尾,我运行这一切,如果这有什么不同?我希望警报像你在freelanc上看到的通知一样当你提交一个项目时,你会在右下角收到一条消息??很高兴它成功了。请检查我的答案是否被接受。对于其他问题,你可以打开一个新的线程,因为它们是关于新事物的。试着非常清楚地说明问题是什么,这样人们也可以帮助你,如果他们从未访问过Freedor.com。。。
jQuery(document).ready(function(){
jQuery("#submit").click(function(){
var points = jQuery("#points]").val();
jQuery(this).prop("disabled", true);
jQuery.ajax({
type: 'POST',
url: MyAjax.ajaxurl,
data: {"action": "updateRedeemPoints", "points":points},
success: function(data){
jQuery("#points-success").show();
}
});
});