佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1151|回复: 1

关于AJAX和php!

[复制链接]
发表于 17-2-2009 10:15 AM | 显示全部楼层 |阅读模式
  1. function ajaxmenu(e, ctrlid, timeout, func, offset) {
  2.         var box = 0;
  3.         showloading();
  4.         if(jsmenu['active'][0] && jsmenu['active'][0].ctrlkey == ctrlid) {
  5.                 hideMenu();
  6.                 doane(e);
  7.                 return;
  8.         } else if(is_ie && is_ie < 7 && document.readyState.toLowerCase() != 'complete') {
  9.                 return;
  10.         }
  11.         cache = 0;
  12.         divclass = 'popupmenu_popup';
  13.         optionclass = 'popupmenu_option';
  14.         if(isUndefined(timeout)) timeout = 3000;
  15.         if(isUndefined(func)) func = '';
  16.         if(isUndefined(offset)) offset = 0;
  17.         duration = timeout > 10000 ? 3 : 0;
  18.         executetime = duration ? 2000: timeout;
  19.         if(offset == -1) {
  20.                 divclass = 'popupmenu_centerbox';
  21.                 box = 1;
  22.         }
  23.         var div = $(ctrlid + '_menu');
  24.         if(cache && div) {
  25.                 showMenu(ctrlid, e.type == 'click', offset, duration, timeout, 0, ctrlid, 400, 0);
  26.                 if(func) setTimeout(func + '(' + ctrlid + ')', executetime);
  27.                 doane(e);
  28.         } else {
  29.                 if(!div) {
  30.                         div = document.createElement('div');
  31.                         div.ctrlid = ctrlid;
  32.                         div.id = ctrlid + '_menu';
  33.                         div.style.display = 'none';
  34.                         div.className = divclass;
  35.                         $('append_parent').appendChild(div);
  36.                 }

  37.                 var x = new Ajax();
  38.                 var href = !isUndefined($(ctrlid).href) ? $(ctrlid).href : $(ctrlid).attributes['href'].value;
  39.                 x.div = div;
  40.                 x.etype = e.type;
  41.                 x.optionclass = optionclass;
  42.                 x.duration = duration;
  43.                 x.timeout = timeout;
  44.                 x.executetime = executetime;
  45.                 x.get(href + '&ajaxmenuid='+ctrlid+'_menu&popupmenu_box='+box, function(s) {
  46.                         evaled = false;
  47.                         if(s.indexOf('ajaxerror') != -1) {
  48.                                 evalscript(s);
  49.                                 evaled = true;
  50.                                 if(!cache && duration != 3 && x.div.id) setTimeout('$("append_parent".removeChild($(\'' + x.div.id + '\'))', timeout);
  51.                         }
  52.                         if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
  53.                                 if(x.div) x.div.innerHTML = '' + s + '';
  54.                                 showMenu(ctrlid, x.etype == 'click', offset, x.duration, x.timeout, 0, ctrlid, 400, 0);
  55.                                 if(func) setTimeout(func + '("' + ctrlid + '"', x.executetime);
  56.                         }
  57.                         if(!evaled) evalscript(s);
  58.                         ajaxerror = null;
  59.                         showloading('none');
  60.                 });
  61.                 doane(e);
  62.         }
  63.         showloading('none');
  64.         doane(e);
  65. }
复制代码
请问以上的代码在写什么?
回复

使用道具 举报


ADVERTISEMENT

发表于 25-2-2009 07:19 AM | 显示全部楼层

其實這裡寫的應該不是完整的代碼. 至少裡面很多的function都看不到.
我猜應該是用AJAX即時去伺服器抓出一個之前已經做好的MENU清並且用DIV的方式顯示出來.
而那個MENU應該是屬於SELECT / OPTION的下來式的的選單.

  1. function ajaxmenu(e, ctrlid, timeout, func, offset) {
  2.         var box = 0;
  3.         showloading();  // 這個function應該是在畫面上顯示出一個"Loading"的字.
  4.         if(jsmenu['active'][0] && jsmenu['active'][0].ctrlkey == ctrlid) {
  5.                 hideMenu(); //如果是之前已經有MENU已經顯示出來就先把那個MENU關掉
  6.                 doane(e); // donee()應該是是done event的意思
  7.                 return;
  8.         } else if(is_ie && is_ie < 7 && document.readyState.toLowerCase() != 'complete') {
  9.                 return; // 如果是IE 7 以下的就跳出
  10.         }
  11.         cache = 0;
  12.         divclass = 'popupmenu_popup'; // 定義div的css class
  13.         optionclass = 'popupmenu_option'; //定義裡面option的css class
  14.         if(isUndefined(timeout)) timeout = 3000;
  15.         if(isUndefined(func)) func = '';
  16.         if(isUndefined(offset)) offset = 0;
  17.         duration = timeout > 10000 ? 3 : 0;
  18.         executetime = duration ? 2000: timeout;
  19.         if(offset == -1) {
  20.                 divclass = 'popupmenu_centerbox';
  21.                 box = 1;
  22.         }
  23.         var div = $(ctrlid + '_menu');
  24.         if(cache && div) {
  25.                 showMenu(ctrlid, e.type == 'click', offset, duration, timeout, 0, ctrlid, 400, 0);
  26.                 if(func) setTimeout(func + '(' + ctrlid + ')', executetime);
  27.                 doane(e);
  28.         } else {
  29.                 if(!div) { //正常的話應該會跑來這裡
  30.                         div = document.createElement('div'); //建立新的DIV
  31.                         div.ctrlid = ctrlid; // 應該是定義control id之類的吧?
  32.                         div.id = ctrlid + '_menu'; // 定義DIV的ID為control ID 加上 "_menu"
  33.                         div.style.display = 'none'; // 把之前那個DIV的css style定義為display: none;
  34.                         div.className = divclass; //為之前那個DIV加上一個叫做 "divclass"的css class
  35.                         $('append_parent').appendChild(div); //把新的DIV附加到parent之下
  36.                 }

  37.                 var x = new Ajax(); // 建立新的AJAX連接
  38.                 var href = !isUndefined($(ctrlid).href) ? $(ctrlid).href : $(ctrlid).attributes['href'].value; //定義AJAX的連接對像.
  39.                 x.div = div;
  40.                 x.etype = e.type;
  41.                 x.optionclass = optionclass;
  42.                 x.duration = duration;
  43.                 x.timeout = timeout;
  44.                 x.executetime = executetime;
  45.                 x.get(href + '&ajaxmenuid='+ctrlid+'_menu&popupmenu_box='+box, function(s) { // 叫AJAX以之前定義的連接去抓取MENU.
  46.                         evaled = false;
  47.                         if(s.indexOf('ajaxerror') != -1) {
  48.                                 evalscript(s); //如果AJAX沒有出錯的話就執行"s"代碼
  49.                                 evaled = true;
  50.                                 if(!cache && duration != 3&& x.div.id) setTimeout('$("append_parent".removeChild($(\'' +x.div.id + '\'))', timeout); //如果時間太長了就放棄
  51.                         }
  52.                         if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
  53.                                 if(x.div) x.div.innerHTML = '' + s + ''; //執行以上的代碼後如果沒有出錯的話就把剛才得到的東西丟在剛建立的DIV裡面.
  54.                                 showMenu(ctrlid, x.etype == 'click', offset, x.duration, x.timeout, 0, ctrlid, 400, 0); // 把MENU顯示出來
  55.                                 if(func) setTimeout(func + '("' + ctrlid + '"', x.executetime);
  56.                         }
  57.                         if(!evaled) evalscript(s);
  58.                         ajaxerror = null;
  59.                         showloading('none'); //把"Loading"的畫面關閉
  60.                 });
  61.                 doane(e); //event 完成.
  62.         }
  63.         showloading('none'); //把"Loading"的畫面關閉
  64.         doane(e); // event 完成!! done!!!
  65. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 21-12-2025 05:42 AM , Processed in 0.124051 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表