ajax三级联动js


2024年6月28日发(作者:厨房用品大全明细表单)

var

//创建XMLHttpRequest对象

function createXMLHttpRequest()

{

if(pRequest)

{

//Mozilla浏览器

XMLHttpReq = new XMLHttpRequest();

}else if(XObject)

{

//IE浏览器

try

{

XMLHttpReq = new ActiveXObject( "P" );

}catch(e)

{

XMLHttpReq,pid;

try

{

XMLHttpReq = new ActiveXObject( "P" );

}catch(e)

{}

}

}

}

//发送Ajax请求

function sendAjaxRequest(url)

{

createXMLHttpRequest(); //创建XMLHttpRequest对象

("post",url,false);

ystatechange = processResponse;//指定响应函数

(null);

}

//回调函数processResponse

function processResponse()

{

if(tate == 4)

{

if( == 200)

{

var allSons = mentsByTagName("son");

var grandfather = mentById("my");

var father = mentById("son");

var son = mentById("grandchild");

if(pid == 0)

{

= 0;

= 0;

= 0;

addOption(grandfather,allSons);

(new Option("请选择",""));

(new Option("请选择",""));

return false;

}

else if(pid == 1)

{

= 0;

= 0;

addOption(father,allSons);

(new Option("请选择",""));

return false;

}

else(pid == 2)

{

= 0;

addOption(son,allSons);

return false;

}

}else

{

//响应未交互成功时,页面中的代码

// "正在加载数据......"

}

}else

{

//响应未加载成功时,页面中的代码

// "正在验证用户名......"

}

}

function addOption(selectObject,allSons)

{

for( var i = 0; i < ; i=i+1 )

{

var allSonsi = allSons[i];

var sonId = mentsByTagName( "sonId" ).item(0).lue;

var sonName =

mentsByTagName( "sonName" ).item(0).lue;

}

if(i == 0)

{

(new Option("请选择",0));

(new Option(sonName,sonId));

}else

{

(new Option(sonName,sonId));

}

}

function getMy(father_id)

{

pid = 0;

var url = "ThreeLink?father_id="+father_id;

var url = "Link?father_id="+father_id;

sendAjaxRequest(url);

//("gff");

}

function getSon(father_id)

{

var father = mentById("son");

var son = mentById("grandchild");

if(father_id == 0)

{

//alert(father_);

= 0;

= 0;

(new Option("请选择",""));

(new Option("请选择",""));

}

else

{

pid = 1;

var url = "Link?father_id="+father_id;

//var url = "ThreeLink?father_id="+father_id;

sendAjaxRequest(url);

}

//("gff");

}

function getGrandchild(father_id)

{

var son = mentById("grandchild");

if(father_id == 0)

{

= 0;

(new Option("请选择",""));

}

else

{

pid = 2;

var url = "Link?father_id="+father_id;

//var url = "ThreeLink?father_id="+father_id;

sendAjaxRequest(url);

}

//("gff");

}