Jaxer 开始

Jaxer 对我来说的确是个挑战,没有太多现成的中文资料,只有通过半懂的英文及已有的代码来学习。

看过些关于Jaxer的评论,多数感到新奇和向往,但更多的人认为这个东西只是一个让人把玩的玩具,缺少实际价值及安全易用的特性。但JAVA最初难道不是供认把玩的玩具么?asp绝比不上jsp的安全却也遍地开花。我们能容忍更多的网络搜素提供商为什么不能在后台代码中接受javascript。用一门语言配合XHTML完成前后台的呈现岂不更为简单及易于维护。

 那么我先记录些我的学习历程和感受

< script  runat ="server" >
            document.write(
"<p>helloworld</p>"+Jaxer.buildNumber);
</ script >

<? php
         
echo      $something ;
?>

起到几乎相同的作用。

看来javascript的运行区域主要靠<script>标签的属性来确定的。

runat=“server”和"client"还有"both"都很容易懂,就不用多说了。

runat="server-proxy"("client-proxy")是指可以在client(server)端调用的代码区域,而该区域的函数等在服务器处理完页面时已经将其以字节码的形式存储在server的内存中,以便于前台的callbacks。

< script  runat ="server-proxy" >
    
function getLastName(firstName) {
        
var lastName = Jaxer.DB.execute("SELECT lastName FROM names WHERE firstName = ?", firstName).singleResult;
        
return lastName;
    }

</ script >
< script >
    
function showFullNameNow() {
        
var firstName = document.getElementById("first").value;
        
var lastName = getLastName(firstName);
        show(firstName, lastName);
    }

    
function showFullNameSoon() {
        
var firstName = document.getElementById("first").value;
        getLastNameAsync(
            
function(lastName) { show(firstName, lastName); }// this is called when getLastName() returns
            firstName);
    }

    
function show(firstName, lastName) {
        alert(firstName 
+ " " + lastName);
    }

</ script >
First name: 
< input  type ="text"  id ="first" >
< input  type ="button"  value ="Show Now"  onclick ="showFullNameNow()" >
< input  type ="button"  value ="Show Soon"  onclick ="showFullNameSoon()" >

大家肯定看到了getLastNameAsync()函数,文档中是这样描述的:

In fact, there are two proxy functions injected into the browser-bound page for every callable server-side function: one with the same name as the server-side function, and one with "Async" appended to its name. The second one is used to make asynchronous calls, ones that don't freeze the browser while the request is made to the server, processed, and returned. The Async version takes an additional first argument: a function to be called when the response is received from the server. That function takes as its arguments the returned result of the server-side function.

没有明白是什么意思,期望有人能给予解答。

属性runat="server-nocache"指的是不被服务器缓存的代码,例如简单的输出,这样可以减轻server的负担,有时还起到些安全的作用。

至于runat="both"或"both-*"理解的并不多。而且还有其他的属性可以完成上述属性的作用,等待下次讨论。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值