分享java带来的快乐

我喜欢java新东西

各种ajax 的json 数据的传递(jquery,prototype,thinkajax)

function showRequest() {
  //alert('before submit!');   
 }
 function reloadCityArr(data){
  var targetSelect=document.getElementById("citySelect");
  clearField(targetSelect)
  for (var i = 0; i < data.length; i++) {   
   var opt = document.createElement("OPTION");
   opt.text=data[i].title;      
   opt.value=data[i].value;  
   targetSelect.add(opt);                           
        }

 }
 
 function clearField(targetSelect){
  
   var listlength=targetSelect.length;

   for (i=listlength-1;i>=0;i--)
         {targetSelect.remove(i);}

 }
//1.prototype方式
 function addChangeProvince(provinceId) {
     var url="__URL__/getCityMap/provinceId/"+provinceId;
   
     new Ajax.Request(url,{
        method: 'get',
        onComplete: function(transport){ 
        reloadCityArr(eval(transport.responseText));        
     }});
 }
//2.jquery
function addChangeProvince(provinceId) {
     var url="__URL__/getCityMap/provinceId/"+provinceId;   
     $.ajax({
         type: "POST",
         url: url,
         data: "name=John&location=Boston",
         dataType:"json",
         success: function(data){
           reloadCityArr(data);   
         
        
        }
     });
 }
//3.thinkajax
 function complete(data,status,info){
  if (status==1){
   reloadCityArr(data);
  }
 }
 function addChangeProvince(provinceId) {
     var url="__URL__/getCityMap/provinceId/"+provinceId;
     ThinkAjax.sendForm('form1',url,complete,'result');
 }

posted on 2011-03-23 23:37 强强 阅读(606) 评论(0)  编辑  收藏 所属分类: web技巧


只有注册用户登录后才能发表评论。


网站导航: