EasyJWeb+prototype

    技术2022-05-11  59

    很久没有写blog了,今天来说说。

    之前大峡写的blog关于EasyJWeb中集成ajax的文章,

    就个人觉得,这样确实能简化了一些Ajax的编写难度,

    从另一个方面,我今天想说一下在某些情况下(该情况其实很普遍)另一个实现Ajax的简单方法,就是EasyJWeb+Prototype

    其实了解Prototype的用户可能已经知道并使用了该方法,今天只是介绍下:

    Prototype中的Ajax.Updater对象能很容易的和EasyJWeb联合起来实现一些ajax应用,

    先来简单的使用一个例子来介绍下Ajax.Updater的使用:

    var myAjax2 = new Ajax.Updater(

                         'cardmain',

                         url2,

                         {

                                method: 'get'

                         }

                  );

    之需要这样,就能完成使用url2来请求服务器段并将返回的HTML内容填充到cardmain中。注意,返回的内容需要是HTML,这正适合EasyJWeb来作。

    首先还是根据请求得到一个html页面,这个页面的内容就是需要填充到浏览器端的内容,比如:

    #foreach($card in $!list)

      <div style="position:absolute;left:$!randomTool.randomRange(200,500);top:$!randomTool.randomRange(50,200); background-color:$!randomTool.randomColor('1fee22');height: 250px; width: 200px; z-index:0; cursor:move"   οnmοusedοwn="f_mdown(this)"   οnmοusemοve="f_move(this)">

          来自:$!card.fro <br>

           发送给: $!card.forwho <br>

           内容: $!card.content <br>

           时间:  $!card.inputTime <br>

      </div>

    #end

     

    然后在调用端使用

    <div id=”cardmain”></div>

    <input type=button name=click onClick=”doUpdate();”>

    就可以了。

     

    该方法的最适合的情况是只需要改变页面某一块的内容。

    并且能很快地将以前的EasyJWeb应用过渡到Web 2.0

    使用该方法,只花了几分钟就能完成一个类似于电话号码查询的那个例子。

    可以试试。

    (本文作者:EasyJF开源团队  stef 欢迎转载,转载请保留作者声明,谢谢!)


    最新回复(0)