2017-05-27 100 views
0

在我的網站上。我有問題與JQuery。我不是這裏的專家,所以請理解。提交JQuery加載問題

這裏是我正在使用它的工作腳本,但是,一旦你點擊提交btn。即使你有一個不完整的信息,表單加載器仍然顯示處理。即使我的董事會說:請填寫你的...,仍然加載gif運行。

腳本:

<script src="//code.jquery.com/jquery-1.10.2.min.js"></script> 
<script> 
$(document).on("click", ".show-page-loading-msg", function() { 
    var $this = $(this), 
    theme = $this.jqmData("theme") || $.mobile.loader.prototype.options.theme, 
    msgText = $this.jqmData("msgtext") || $.mobile.loader.prototype.options.text, 
    textVisible = $this.jqmData("textvisible") || $.mobile.loader.prototype.options.textVisible, 
    textonly = !!$this.jqmData("textonly"); 
    html = $this.jqmData("html") || ""; 
$.mobile.loading('show', { 
    text: msgText, 
    textVisible: textVisible, 
    theme: theme, 
    textonly: textonly, 
    html: html 
    }); 
}) 
.on("click", ".hide-page-loading-msg", function() { 
    $.mobile.loading("hide"); 
}); 
</script> 

我的PHP代碼:(這是不完整的,我只是想分享的端部)

<div class="form-group"> 
        <div class="col-md-5 col-sm-8 col-xs-8"> 
         <?if (Core::config('general.recaptcha_active')):?> 
          <?=Captcha::recaptcha_display()?> 
          <div id="recaptcha3"></div> 
         <?else:?> 
          <?= FORM::label('captcha', _e('Captcha'), array('for'=>'captcha'))?> 
          <span id="helpBlock" class="help-block"><?=captcha::image_tag('publish_new')?></span> 
          <?= FORM::input('captcha', "", array('class' => 'form-control', 'id' => 'captcha', 'required', 'data-error' => __('Captcha is not correct')))?> 
         <?endif?> 
        </div> 
       </div> 
      <?endif?> 
      <div class="control-group"> 
       <div class="controls"> 
         <?= FORM::button('submit', __('<i class="glyphicon glyphicon-send"></i>&nbsp; Publish New Ad'), array('type'=>'submit', 'data-corners'=>'false', 'class'=>'pub-new show-page-loading-msg', 'data-theme'=>'b', 'data-textonly'=>'false', 'data-msgtext'=>'Processing....', 'data-textvisible'=>'true', 'action'=>Route::url('post_new',array('controller'=>'new','action'=>'index'))))> 
       </div> 
      </div> 
     </fieldset> 
    <?= FORM::close()?> 

瞭解更多請你可以去這裏,但你需要使用手機查看:https://linkinads.com/publish-new.html或在這裏的YouTube視頻:https://www.youtube.com/watch?v=dKzabE2eJN0

回答

0

您的按鈕是一個提交按鈕。這些按鈕觸發一個事件,以便在HTML中原生處理表單。

在你的Javascript中,你不應該將你的代碼綁定到按鈕類的click事件上,而應該將它綁定到表單的提交事件上(它與整個按鈕和表單綁定)然後阻止默認提交操作。像下面的東西。

$('#publish-new').submit(function(event) { 
    event.preventDefault(); //Prevents the default form event from firing 
    //Rest of your code can go here 
}); 
+0

你的意思是這樣的:https://codepen.io/DonPramis-dubai/pen/WjBbZY –

+0

或者我需要在這裏編輯表單的開頭:<= FORM :: open(Route :: url('post_new' ,'array'('controller'=>'new','action'=>'index')),array('class'=>'form-horizo​​ntal','enctype'=>'multipart/form-data',' data-ajax'=>'false'))?>' –

+0

請在這裏顯示我不是專家。謝謝 –

1

雖然我不知道這裏發出的真實的,但我這個移動後,東西是固定的

'data-ajax'=>'false'

解決我的問題。