標籤:style blog http color os 檔案
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+="¬e="+_._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;
}