html5实现ajax上传文件

var formData = new FormData();
formData.append('name', tr.find('input[name="name"]').val());

if (tr.find('input[name="logo"]')[0].files[0] !== undefined) {
    formData.append('logo', tr.find('input[name="logo"]')[0].files[0]);
}
$.ajax('http://example.com/abc/upload/', {
    type: 'POST',
    cache: false,
    data: formData,
    dataType: 'json',
    processData: false,
    contentType: false,
    success: function(result) {
        console.log('保存成功');
    },
    error : function (msg) {

    },
});

html前端处理GET参数两个基类方法备忘

function ObjectToStr(obj) {
    var result = '';
    $.each(obj, function(k, v){
        if (result === '') {
            result = '?' + k + '=' + v;
        } else {
            result += '&' + k + '=' + v;
        }
    });
    return result;
}


function getParams() {
    var url = window.document.location.href.toString();
    var u = url.split("?");
    if(typeof(u[1]) == "string"){
        u = u[1].split("&");
        var get = {};
        for(var i in u){
            var j = u[i].split("=");
            get[j[0]] = j[1];
        }
        delete get.page;
        return get;
    } else {
        return {};
    }
}