Uncaught TypeError:无法读取未定义的属性'action'

问题描述 投票:0回答:1

大家好,我要创建一个动态的jquery函数以将所有记录保存在一个函数中,但是我无法执行form操作。请帮助我。

这是我的刀片文件

   {!! Form::open(array('route' => 'area.store','method'=>'POST')) !!}
         <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel1">@lang('layout.AddNewArea')</h5> 
             <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                   <span aria-hidden="true">&times;</span>
              </button>
         </div> 
         <div class="modal-body">
            <fieldset class="form-group col-12" >
              <div :class="{ 'has-error': errors.has('name') || serverError.name && !(fields.name.dirty) }">
                 <span v-if="serverError.name && !(fields.name.dirty) " class="help-block">  {{$errors->first('name')}}</span>
                  {Form::text('name',null,['class'=>'form-control','v-validate'=>"'required|min:3'",'placeholder'=>__('layout.Name'),'required' ])}}
                  <span style="color:red" v-if="errors.has('name')" v-bind:value="serverError.name = false" class="help-block">@{{ errors.first('name') }}</span>
             </div>
           </fieldset>
           <fieldset class="form-group col-12">
             <input v-model="code" type="text" id="contact-email" class="contact-email form-control" placeholder="@lang('layout.Code')" name="code">
            </fieldset>
           <fieldset class="form-group col-12">
          <textarea type="text" id="contact-phone" class="contact-phone form-control" placeholder="@lang('layout.Description')"></textarea>
            </fieldset>  
      </div>
     <div class="modal-footer">
     <fieldset class="form-group position-relative has-icon-left mb-0">
     <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-paper-plane-o d-block d-lg-none"></i> <span class="d-none d-lg-block" >@lang('layout.Cancel')</span></button>
   <button  type="button" onclick="savetest(this,'area')" class="btn btn-primary"><i class="fa fa-paper-plane-o d-block d-lg-none"></i> <span class="d-none d-lg-block" >@lang('layout.Submit')</span></button>
    </fieldset>
  </div>
{!! Form::close() !!}

这是我的jquery函数

 function  testSave(element) {
                var e = $(element);  
                console.log(e); 
                var form = e.parent('form').get(0);
                var url= $(form).get(0).action;
                console.log(url);
                var table=$(datatableId).DataTable();
                $.ajax({
                  method:"POST",
                  data:$(this).serialize(),
                  dataType:"json",
                  url:url,
                  headers: {'X-CSRF-TOKEN': "{{csrf_token()}}"},
                  success: function(result)
                  {

                    table.ajax.reload();
                    $('#new_record').modal('hide');

                  },
                  error:function(error){
                      console.log('fghjkl',error);
                  }
              }); 
        } 

这是错误erro image

javascript jquery laravel forms action
1个回答
0
投票

检查页面源代码以查看表单“操作”是否存在并且有效。试试var url= form.action;

© www.soinside.com 2019 - 2024. All rights reserved.