AJAX读取模板文件并替换模板中的标签

下载地址

http://pan.baidu.com/share/link?shareid=238886&uk=1680261748

 





AJAX读取模板文件并替换模板中的标签



用AJAX从服务器文件读取模板文件,并替换模板中的标签。

<%html template1.tml %>
<%html template2.tml %>

 

template1.tml

{tag:tit1}

{tag:con1}

 

template2.tml

{tag:tit2}

{tag:con2}

 

ajax.js

function ajax(sURL, fnOnSucess, fnOnFail)
{
var oAjax = null;

if(window.ActiveXObject)
{
oAjax = new ActiveXObject('Microsoft.XMLHTTP');
}
else
{
oAjax = new XMLHttpRequest();
}

oAjax.open('GET', sURL, true);

oAjax.onreadystatechange = function () {
if(oAjax.readyState == 4)
{
if(oAjax.status == 200)
{
fnOnSucess(oAjax.responseText);
}
else
{
fnOnFail(oAjax.status);
}
}
};

oAjax.send(null);
}

function ajaxPost(sURL, data, fnOnSucess, fnOnFail)
{
var oAjax = null;

if(window.ActiveXObject)
{
oAjax = new ActiveXObject('Microsoft.XMLHTTP');
}
else
{
oAjax = new XMLHttpRequest();
}

oAjax.open('POST', sUrl, true);

oAjax.onreadystatechange = function () {
if(oAjax.readyState == 4)
{
if(oAjax.status == 200)
{
fnOnScuess(oAjax.responseText);
}
else
{
fnOnFail(oAjax.status);
}
}
};

oAjax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

oAjax.send(data);
}

转载于:https://www.cnblogs.com/baie/archive/2013/02/18/2916047.html

你可能感兴趣的:(AJAX读取模板文件并替换模板中的标签)