js/jquery 页面传值

function saveintroduce() {

    var ajax = false;
    //开始初始化XMLHttpRequest对象
    if (window.XMLHttpRequest) { //Mozilla 浏览器
        ajax = new XMLHttpRequest();
        if (ajax.overrideMimeType) { //设置MiME类别
            ajax.overrideMimeType("text/xml");
        }
    } else if (window.ActiveXObject) { // IE浏览器
        try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                ajax = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {}
        }
    }
    if (!ajax) { // 异常,创建对象实例失败
        window.alert("不能创建XMLHttpRequest对象实例.");
        return false;
    }
    
    var postStr = 'nick='+_._trim($("dt_join_form_nick").value);
    postStr+="&phone="+_._trim($("dt_join_form_phone").value);
    postStr+="&note="+_._trim($("dt_join_form_note").value);
    postStr+="&db="+getParam("db");
    postStr+="&id="+getParam("twid");
    //通过Post方式打开连接
    ajax.open("POST", "saveData.php", true);
    //定义传输的文件HTTP头信息
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //发送POST数据
    ajax.send(postStr);
    //获取执行状态
    ajax.onreadystatechange = function() {
        //如果执行状态成功,那么就把返回信息写到指定的层里
        if (ajax.readyState == 4 && ajax.status == 200) {
            if(ajax.responseText=="ok"){
              alert("报名成功~");
            }
            if(ajax.responseText=="have")
            {
              alert("您已经报过名了~");
            }
             $("dt_join_form_nick").value="";
              $("dt_join_form_phone").value="";
              $("dt_join_form_note").value="";
              self.location.reload();
        }
    }
}
</script>

js接受url传值的方法:

function getParam(paramName) {
    var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)");
    var url = window.location.search.substr(1).match(reg);
    if (url != null) return unescape(url[2]);
    return null;
    }

原文地址:https://www.cnblogs.com/lijun2013/p/3861151.html