1
我正在使用velocity模板語言和javascript聯繫我們頁面。如何在速度模板語言中調用ajax調用?
要求 一)從兩個下拉列表(位置和SHOPNAME)和客戶選擇值點擊提交按鈕
b)使用AJAX調用(處理此過程中不會對刷新頁面),並顯示地址正下方的下拉同一頁
我開發了用於表單的UI界面(在contact.vtl上)。點擊事件後,我可以調用AJAX調用,之後,控制轉移到contact-detail.vtl,在這裏我無法繼續進行?
如何發回迴應contact.vtl?
function ajaxCall(){
function getXMLRequestObject() {
if(window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert("Your Browser does not support AJAX!! .Upgrade to latest version");
}
}
var url="/application/vtl/widgets/contact-us/contact-detail.vtl?loc=XYZ&shop=ABC";
var userContactReq = getXMLRequestObject();
if (userContactReq.readyState === 1 || userContactReq.readyState === 2 || userContactReq.readyState === 3) {
userContactReq.abort();
}
userContactReq = getXMLRequestObject();
if (userContactReq.readyState === 4 || userContactReq.readyState === 0) {
userContactReq.open("GET",url,true);
userContactReq.onreadystatechange = setReqSuccess;
userContactReq.send(null);
}
function setReqSuccess() {
if(userContactReq.readyState === 4){alert("Ready State is 4");}
if(userContactReq.status === 200){alert("Status is 200");}
if(userContactReq.readyState === 4 && userContactReq.status === 200) {
## How to recieve response here
var responseString = userContactReq.responseText;
console.log("end");
alert(responseString);
}
}
}
Hi @Sran! jQuery將爲您節省所有的鍋爐板。 – joshuamabina