本文实例讲述了双层ajax嵌套(可多层)用法。分享给大家供大家参考。具体如下:
function addbus() { //清除a标签中的所有元素 // $("#s1").remove(); var chooseIdTypeOne =$("#chooseIdTypeOne2").find("option:selected").val(); $.ajax({ url : "/ftcms/changeProject.do?getOriginal&OriginalName="+chooseIdTypeOne, data : null, // 参数 type : "post", cache : false, dataType : "json", //返回json数据 error: function(){ //document.getElementById("chooseIdTypeOnechdranone").options.length = 0; alert('error'); }, success:onchangecal }); } function onchangecal(data){ var chooseIdTypeOne =$("#chooseIdTypeOne2").find("option:selected").val(); document.getElementById("chooseIdTypeOnechdranone2").options.length = 0; //清空原有的option var str=""; if(chooseIdTypeOne==1){ $.ajax({ url : "/ftcms/changeProject.do?getOriginal&OriginalName="+chooseIdTypeOne, data : null, // 参数 type : "post", cache : false, dataType : "json", //返回json数据 error: function(){ //document.getElementById("chooseIdTypeOnechdranone").options.length = 0; alert('error'); }, success:onchangecal }); } } } if(chooseIdTypeOne==2){ for(var i=0;i"+data[i].NAME+"" } } if(chooseIdTypeOne==3){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==4){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==5){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==6){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==7){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==8){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==9){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==10){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==11){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==12){ for(var i=0;i "+data[i].NAME+"" } } if(chooseIdTypeOne==13){ for(var i=0;i "+data[i].NAME+"" } } $("#chooseIdTypeOnechdranone2").html(str); }
希望本文所述对大家的Ajax程序设计有所帮助。