jquery-ui dialog, ajax FormData [snippet]

html:

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div id="dialog" title="Basic dialog">
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>

  

javascript:

// http://api.jqueryui.com/dialog/
var $dlg = $("#dialog-1");
$dlg.dialog({
	autoOpen: false,
	minWidth: 200,
	resizable: true,
	modal: false,
	create: function() {},
	open: function() {},
	close: function() {},
	buttons: [
		{
			text: "取消",
			icon: "ui-icon-arrowreturnthick-1-w",
			click: function() {
				$( this ).dialog( "close" );
			}
		},
		{
			text: "确定",
			icon: "ui-icon-check",
			click: function() {
				// do something
				$(this).dialog("close");
			}
		}
	]
});
$dlg.dialog("open");

  

FormData upload file

var form = document.getElementById("form_insert"),
	data = new FormData(form);
data.append("image", img1);

$.ajax({
	type: 'POST',
	url: window.CONTEXT_PATH + "/school/schoolImage",
	data: data,
	cache: false,
	contentType: false,
	processData: false,
	dataType: "json"
}).done(function(data) {
	/*
	require(['alert'], function(m) {
		if (data.status === 200) {
			m.alert.getInstance().success("插入图片到图集" + form.title.value);
		} else {
			m.alert.getInstance().fail(data.msg || data.error);
		}
	});
	$dlg1.dialog("close");
	*/
}).fail(function(jqXHR, textStatus, errorThrown) {

});

  

猜你喜欢

转载自www.cnblogs.com/mingzhanghui/p/9268136.html