微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – webix UI模式中的表单数据

我正在使用Webix UI模式,这就是我使用它的方式:
this.add = function () {
scrollArea.css("overflow","hidden");
$.ajax({
	type: "GET",url: "/detail/create",success: function (form) {
		webix.message.keyboard = false;
		webix.modalBox({
			title: "New detail",buttons: ["Accept","Decline"],text: form,width: 400,callback: function (result) {
				switch (result) {
					case "0":
						addDetail();
						break;
					case "1":
						break;
				}
				scrollArea.css("overflow","auto");
			}
		});
	}
});
function addDetail() {
	$.ajaxSetup({
		headers: {
			'X-CSRF-TOKEN': $('Meta[name="csrf-token"]').attr('content')
		}
	});
	$.ajax({
		type: "POST",url: "/detail/store",data: $('#detail_add').serialize(),contentType: "JSON",processData: false,success: function () {
		}
	});
}
};


And form's HTML:
<form action="" id="detail_add" method="post">
<input type="text" name="name" placeholder="Name">
<input type="text" name="article" placeholder="Article">
<input type="hidden" name="location_id" placeholder="1">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
</form>

当我单击模态中的接受时,我的JSON为空.我该如何解决
我试图通过console.log获取输入值,但它也是空的.

解决方法

这不是一般的答案,但示例代码不适用于解决问题,因为:

>我们不知道什么是scrollArea对象
>您尝试实现依赖于我们没有的成功脚本响应的代码
>我们没有启动代码的操作按钮

以下是稍微更改的代码,以演示您的案例:

我正在使用Webix UI模式,这就是我使用它的方式:

scrollArea = $(window.document);
this.add = function() {

  //scrollArea.css("overflow","hidden");

  $.ajax({
    type: "GET",beforeSend: function(form) {
      webix.message.keyboard = false;
      webix.modalBox({
        title: "New detail",callback: function(result) {
          switch (result) {
            case "0":
              addDetail();
              break;
            case "1":
              break;
          }
          scrollArea.css("overflow","auto");
        }
      });
    }
  });

  function addDetail() {
    $.ajaxSetup({
      headers: {
        'X-CSRF-TOKEN': $('Meta[name="csrf-token"]').attr('content')
      }
    });

    $.ajax({
      type: "POST",success: function() {}
    });
  }
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<link rel="stylesheet" href="http://cdn.webix.com/edge/webix.css" type="text/css">
<script src="http://cdn.webix.com/edge/webix.js" type="text/javascript"></script>

<form action="" id="detail_add" method="post">
  <input type="text" name="name" placeholder="Name">
  <input type="text" name="article" placeholder="Article">
  <input type="hidden" name="location_id" placeholder="1">
  <input type="hidden" name="_token" value="{{ csrf_token() }}" />
  <button onClick="add()">Add</button>
</form>

当我单击模态中的接受时,我的JSON为空.我该如何解决?我试图通过console.log获取输入值,但它也是空的.

原文地址:https://www.jb51.cc/js/156969.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐