• 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) {
    });
    

      

  • 相关阅读:
    博客园电子期刊2012年6月刊发布啦
    如何在博客园发博客时插入优酷视频
    上周热点回顾(7.167.22)
    “Coding changes the world” 博客园2012主题T恤专题上线
    [转]MySql查询缓存机制
    淘宝店铺开发 ShopSDK 1.x 及 TAE_SDK 2.0
    [转]NHibernate之旅系列文章导航
    MySQL 5.1参考手册 :: 7. 优化
    [转]Nant daily build实践
    [转]淘宝sdk——入门实战之footer.php制作
  • 原文地址:https://www.cnblogs.com/mingzhanghui/p/9268136.html
Copyright © 2020-2023  润新知