• AJAX扩展-POST传递参数并跳转页面


    拓展的代码:

    这段代码的原理是创建一个表单,所有args都创建一个隐藏的input,用post方法把这些参数传递过去

    注意form表单一定要加载到页面中,即下面代码中标红的部分,不然参数是无法被传递的(因为这个被坑了)

        $.extend({
            StandardPost:function(url,args){
                var form = $("<form method='post'></form>"),
                    input;
            //jquery方式 $(document.body).append(form);
            //js原生添加
            //document.body.appendChild(form);
    form.attr({
    "action":url}); $.each(args,function(key,value){ input = $("<input type='hidden'>"); input.attr({"name":key}); input.val(value); form.append(input); }); console.log(args); form.submit(); } });

    简单调用:

    $.StandardPost('url/path/req',{arg0:'arg0',arg1:'arg1'}); 

    获取url链接传递的参数

        var Request = new Object();
        Request = GetRequest();
        function GetRequest() {
            var url = location.search; //获取url中含"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
                }
            }
            console.log(theRequest)
            return theRequest;
        }

    这是用post方法跳转页面,即跳转的页面是不带后面的参数的

    当然也可以直接用get方法,直接链接跳转携带返回参数

    比如:

    window.location.href = "/?go="+Request["go"]+"&arg0="+Request["arg0"]+"&arg1="+Request["arg1"];
  • 相关阅读:
    List of the best open source software applications
    Owin对Asp.net Web的扩展
    NSwag给api加上说明
    'workspace' in VS Code
    unable to find valid certification path to requested target
    JMeter的下载以及安装使用
    exception disappear when forgot to await an async method
    Filter execute order in asp.net web api
    记录web api的request以及response(即写log)
    asp.net web api的源码
  • 原文地址:https://www.cnblogs.com/calamus/p/7886089.html
Copyright © 2020-2023  润新知