即使邮件没有发送,为什么我的提交按钮仍然隐藏?

时间:2016-07-23 10:33:49

标签: javascript ajax contact-form

任何想法为什么我的提交按钮隐藏无论什么(消息已成功发送或未发送)。

当消息没有发送时,我可以看到#error_message出现(这是正常的),但我仍然希望提交按钮仍然可见(允许用户再试一次)< / p>

由于

start = (Button) v.findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            updatePlayer();
        }

private void updatePlayer() {  
final Iterator<DataSnapshot> playerIterator = dataSnapshot.getChildren().iterator(); 

mDatabase.child("Challenger").child("Pro").child(challengerKey).runTransaction(new Transaction.Handler() {
                                @Override
                                public Transaction.Result doTransaction(MutableData currentData) {


                                    if (currentData.getValue().toString() != null) {

                                        foundChallenger = currentData.getValue().toString();

                                        // Remove from server
                                        mDatabase.child("Challenger").child(state.getPlayer().getRank()).child(challengerKey).removeValue(new DatabaseReference.CompletionListener() {
                                            @Override
                                            public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                                                Log.d(GoogleServiceApi.TAG, "removeValueOnComplete");
                                                Log.d(GoogleServiceApi.TAG, "databaseError" + databaseError);                                                   
                                            }
                                        });

                                        // Add new data to player node
                                        ArrayList<String> newChallengerList;


                                        newChallengerList = new ArrayList<String>();
                                     newChallengerList.add(foundChallenger);

                                        Map<String, Object> challengerUpdates = new HashMap<>();
                                        challengerUpdates.put("challengerList", newChallengerList);

                                        mDatabase.child("Player").child(state.getUid()).updateChildren(challengerUpdates);


                                    } else {
                                        Log.d(GoogleServiceApi.TAG, "no current data!");
                                        return Transaction.abort();
                                    }

                                    return Transaction.success(currentData);
                                }

                                @Override
                                public void onComplete(DatabaseError databaseError, boolean committed, DataSnapshot dataSnapshot) {
                                    Log.d(GoogleServiceApi.TAG, "committed: " + committed);
                                    Log.d(GoogleServiceApi.TAG, "databaseError: " + databaseError);
                                    Log.d(GoogleServiceApi.TAG, "databaseError: " + dataSnapshot);

                                    if (!committed) {

                                    }

                                }
                            }, false);

                        } catch (NoSuchElementException e) {
                            Log.d(GoogleServiceApi.TAG, "no challenger currently!");
                        }
 }

1 个答案:

答案 0 :(得分:0)

按下提交$('button[name="submit"]').hide();

后,您正在隐藏它

发生错误时,您可以再次显示该按钮

$.post($(this).attr('action'), $(this).serialize(), function (result) {
    if (result.status == 1) {
        $('#success_message').slideDown({
            opacity: "show"
        }, "slow")
        $('#contact_form').data('bootstrapValidator').resetForm();
    } else {
        $('#error_message').slideDown({
            opacity: "show"
        }, "slow")     
        // show the button again
        $('button[name="submit"]').show();         
    }
}, 'json');