/javascript/GET.js

https://github.com/pipifuyj/global · JavaScript · 38 lines · 30 code · 0 blank · 8 comment · 6 complexity · a223e0211c5010a9e1b9df6e6b612e75 MD5 · raw file

  1. //version: Liu ChuanRen, 02/20/08
  2. var _GET={};
  3. var _GET_ok=false;
  4. /*
  5. name="a[b][c][d]", value="e", the result of _GET_set:
  6. _GET["a"]={};
  7. _GET["a"]["b"]={};
  8. _GET["a"]["b"]["c"]={};
  9. _GET["a"]["b"]["c"]["d"]="e";
  10. */
  11. function _GET_set(name,value){
  12. name=name.replace(/]/g,"");
  13. name=name.split("[");
  14. var i,j,t,s;
  15. for(i=0;i<name.length;i++){
  16. t="";
  17. for(j=0;j<=i;j++){
  18. t+="[\""+name[j]+"\"]";
  19. }
  20. eval("if(typeof _GET"+t+"==\"undefined\")_GET"+t+"={};")
  21. }
  22. eval("_GET"+t+"=\""+value+"\";");
  23. }
  24. function GET(name,url){//url: http://server?query_string&name=value&time&a[b][c][d]=e
  25. if(_GET_ok){
  26. }else{
  27. if(!url)url=location.toString();
  28. url=url.substring(url.indexOf("?")+1);
  29. url=url.split("&");
  30. var i,temp;
  31. for(i=0;i<url.length;i++){
  32. temp=url[i].split("=");
  33. _GET_set(temp[0],temp[1]);
  34. }
  35. }
  36. if(typeof _GET[name]=="undefined")_GET[name]="";
  37. return _GET[name];
  38. }