仅当json响应为真时才启用下一个按钮(转到另一个选项卡)?

时间:2017-12-28 04:17:39

标签: javascript jquery html json vue.js

这是html表格

services.AddMvc(options =>
            {
                options.ModelBinderProviders.Insert(0, new PersianCharsBinderProvider());
            });

数据来自

我的vue js脚本是

我只添加了ajax请求

    <div class="tab-pane" id="step1">
    <form method="POST" onSubmit="return false;" data-parsley-validate="true" v-on:submit="handelSubmit($event);">  
     **DATA COMES HERE**
    <div class="wizard-footer">
    <div class="pull-right">
    <button type="submit" class='btn btn-next btn-primary' name='next' value='Next'>Next</button>
</form>
    </div>

只有成功,才需要转到下一个标签。但现在如果发生任何事情,它将转移到下一个标签。只有当状态为true时,如何使按钮移动到下一个选项卡。仅在警报消息成功时。我需要转到下一个标签。请帮我解决问题?

1 个答案:

答案 0 :(得分:1)

正如MRustamzade提到的那样有正确的答案

默认情况下,按钮上禁用了.add

<div class="tab-pane" id="step1">
    <form data-parsley-validate="true" >  
     **DATA COMES HERE**
    <div class="wizard-footer">
    <div class="pull-right">
    <button type="submit" class='btn btn-next btn-primary' disabled name='next' value='Next'>Next</button>
    </form>
</div>

2.仅当e.success = true

时才禁用删除
$('form').submit(function(e){
    var data = $(this).serializeArray();
    var btn= $(this).find('.btn-next');
    var btnText = btn.text();
    $.ajax({
        url: 'http://127.0.0.1:8000/post/',
        data: data,
        type: "POST",
        dataType: 'json',
        beforeSend: function(){
            btn.prop('disabled', true).removeClass('.btn-primary').addClass('.btn-warning').text('wait');
        },
        success: function(e) {
        if (e.status)
          {
            btn.removeClass('.btn-warning').addClass('.btn-success').text('success');
            vm.pid=e.pid;
                        setTimeout(function(){
                            btn.prop('disabled',false).removeClass('.btn-success').addClass('.btn-primary').text(btnText);
            },2000);
        }
          else {
                        btn.removeClass('.btn-warning').addClass('.btn-danger').text('failed');
            vm.response = e;
            setTimeout(function(){
                            btn.removeClass('.btn-danger').addClass('.btn-primary').text(btnText);
            },2000);
          }


        },
        error: function(e){
            console.log(e); //for debug the error msg
            btn.removeClass('.btn-warning').addClass('.btn-danger').text('error');
            setTimeout(function(){
                btn.removeClass('.btn-danger').addClass('.btn-primary').text(btnText);
            },2000);
        }
    });
});