AJAX如何将参数带到并传给另一个页面?

1.、先在当前页面进行操作

tableData.ChangeA = function (rowData) {
    window.location.href="/adD?deptCode=" + rowData.deptId + '&month=' + rowData.month; //window.location.href跳转新页面
};

2、在另一个页面对链接进行解析

function parseUrl(url){
    var query = url.split("?")[1];
    var queryArr = query.split("&");
    var obj = {};
    queryArr.forEach(function(item){
        var key = item.split("=")[0];
        var value = item.split("=")[1];
        obj[key] = decodeURIComponent(value);
    });
    return obj;
}
// url传递的信息
var urlMsg = parseUrl(window.location.search);

3、对参数进行解析:

$.ajax({
    url:'/attend/getByDept?deptCode='+urlMsg.deptCode+'&month='+urlMsg.month,
    method: 'get'
})
.done(function (msg) {
})
 
 

猜你喜欢

转载自blog.csdn.net/weixin_39717076/article/details/80220785