출처 : http://forums.delphi-php.net/javascript-ajax/3017-favorite-functions-add-common-js.html

Delphi for PHP 설치폴더에서 vcl/js/common.js 를 연다.

파일 제일 하단에 아래의 코드 추가

 vcl=
{
$:function ()
{
var elements = new Array();
for (var i = 0; i < arguments.length; i++)
{
var element = arguments[i];
if (typeof element == 'string')
element = findObj(element);
if (arguments.length == 1)
return element;
elements.push(element);
}

return elements;
},
int:function(obj){ return parseInt(vcl.$(obj).value);},
real:function(obj){ return parseFloat(vcl.$(obj).value);},
escape:function(obj){ return escape(vcl.$(obj).value);},
unescape:function(obj){ return unescape(vcl.$(obj).value);},
focus:function(obj){ vcl.$(obj).focus();},
check:function(obj){ vcl.$(obj).checked=true;},
uncheck:function(obj){ vcl.$(obj).checked=false;},
hide:function(obj){ vcl.$(obj).style.display = 'none';},
show:function(obj){ vcl.$(obj).style.display = '';},
find:function(obj){ return vcl.$(obj);},
text:function(obj){ return vcl.$(obj).value;},
value:function(obj){ return vcl.$(obj).value;},
setOpacity:function(incoming,value)
{
theObj=vcl.$(incoming);
theObj.style.opacity = value/10;
theObj.style.filter = 'alpha(opacity=' + value*10 + ')';
}
}

function createHTTPrequest()
{ /* Firefox, Opera 8.0+, Safari */
try {return new XMLHttpRequest();}
catch (error) {}
/* newer IE */
try {return new ActiveXObject("Msxml2.XMLHTTP");}
catch (error) {}
/* older IE */
try {return new ActiveXObject("Microsoft.XMLHTTP");}
catch (error) {}
throw new Error("Your browser does not have AJAX support!");
}
function basicAjax (url,parameters,callback)
{
xmlHttp=createHTTPrequest();
if (callback) {xmlHttp.onreadystatechange=callback;}
else
{
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
if (xmlHttp.status == 200)
{eval(xmlHttp.responseText);}
else
{alert("Sorry, received a server error ="+xmlHttp.statusText);}
}
}
}
xmlHttp.open("POST",url,true);
if (typeof(basicAjaxAsyncFalse) != 'undefined' && basicAjaxAsyncFalse==1) xmlHttp.open("POST",url,false); //this will force a wait for return
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59GMT");
xmlHttp.send(parameters);
}

Basic Ajax사용법

  //call basicAjax but override the eval function
basicAjax("ajax_server.php","value1=Bob",myfunction);

//call basicAjax using the built in eval function
var params='value1='+vcl.$('Edit1').value+'&value2='+vcl.$('Edit2').value;
basicAjax("ajax_server1.php",params);

vcl.$() 사용법

 // Sample Usage:
               function Button2JSClick($sender, $params)
               {

               ?>
alert(vcl.$('Edit1').value);//just get one object

//these 3 are identical
var obj1 = document.getElementById('Edit1');
var obj2 = vcl.$('Edit1');
var obj3= FindObj('edit1');

 vcl.$('Edit1').disabled;

//this gets an array of objects!! (includes obj we all ready had found also
// and real objects like LabeledEdit)
var elements = vcl.$('Edit2','Edit4','Edit6',obj1,obj2,'Edit5','Edit3');
for (var i=0;i < elements.length; i++) elements[i].value='';
//we just blew through a bunch of edits and cleared them.
// fyi this wouldn't work this way with the labeled edits though - they need setValue('')
               <?php

               }

 

 // Sample Usage:
vcl.hide('Button1');
vcl.show('Button1');

 

'자료들 > Delphi for PHP' 카테고리의 다른 글

BasicAjax 및 JQuery식 표현 사용하기  (0) 2009.10.07
SmartyTemplate 사용하기  (2) 2007.06.25
Memo Class 사용법  (0) 2007.06.25
Layout.Type 속성  (0) 2007.06.24
Posted by 화니.

댓글을 달아 주세요