jquery-ui dialog, ajax FormData [snippet], $.ajax setRequestHeader
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) { });
* $.ajax setRequestHeader 修改http协议头
$.ajax({ type: 'GET', url: window.CONTEXT_PATH + "/school/listSchoolAlbumType", data: {schoolName: schoolName}, beforeSend: function(xhr) { xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"); xhr.setRequestHeader("Accept-Language", "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,ja;q=0.6"); } }).done(function(data) { });