---
title: "初探JAXER"
author: "fastwind"
date: "2008-04-14T09:46:33Z"
tags: []
slug: "jaxer"
draft: false
lastmod: "2008-04-14T09:46:33Z"
id: 182476
url: "https://fastwind.iteye.com/blog/182476"
---

昨天更新Aptana的时候发现Aptana网站上多了一个JAXER,不知为何物。google了一把也只找到一个介绍的翻译，再回网站上看了一下，原来是22日刚发布的。不过看过简单介绍后，觉得最吸引人的地方就是这几张图  
![](http://aptana.com/system/files/images/Picture+2.png)  
![](http://aptana.com/system/files/images/Picture+4_0.png)  
![](http://aptana.com/system/files/images/Picture+3_0.png)![](http://aptana.com/system/files/images/Picture+2_0.png)  
     直接运行htm页面，服务器端运行的javascript,服务器端和浏览器端都能运行的方法,还有可以从浏览器端调用的服务器端的方法，有点意思，感觉有点像asp.net。马上研究了一下它的API文档（[http://aptana.com/reference/jaxer/api/Jaxer.index-frame.html](http://aptana.com/reference/jaxer/api/Jaxer.index-frame.html)），基本的东西都全了，数据库支持mySql和SQLite。  
    SQLite使用太方便了，找了一个SQLiteSpy带的world.db3数据库，使用最新的Aptana（已经包括了JAXER插件和服务器)，结合jquery做了一个简单的例子。

全部代码如下：

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;html&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;head&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf8"/&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;title&gt;Untitled Document&lt;/title&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)        &lt;script language=javascript src=lib/jquery/jquery.js&gt;...  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)        &lt;/script&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)        &lt;script runat=server-proxy&gt;...  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            function getTable(rows)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                var a = new Array();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                a\[0] = rows;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)                var conn = new Jaxer.DB.SQLite.Connection(...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                    PATH: "E:\\test\\sqlite\\world.db3"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)                });  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                var rs = conn.execute("Select * from \[City] where id &lt;= ?", a);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                return (rs.toHTML());  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)            }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)        &lt;/script&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)        &lt;script language=JavaScript&gt;...  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            $(function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)                $("#button1").click(function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                    $("#div1").append(getTable(1000));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)                });  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)                $("#button2").click(function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                    getTableAsync(setdata, 1000)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)                });  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)                $("#button3").click(function()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                    $("#div1").html("");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)                });  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)            });  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)            function setdata(table)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)                $("#div1").html(table);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)            }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)              
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)        &lt;/script&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;/head&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;body&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;input type=button id=button1 value=同步方法&gt;&lt;input type=button id=button2 value=异步方法&gt;&lt;input type=button id=button3 value=清除&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;div id=div1&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)        &lt;/div&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)    &lt;/body&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/html&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

运行截图：  
![](http://www.cnblogs.com/images/cnblogs_com/luq885/test.JPG)  
    详细的就不说了，关键是

&lt;script runat=server-proxy&gt;...&lt;/script&gt;这部分，在客户端生成了这么两个方法：

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)function getTable() ...{return Jaxer.remote("getTable", arguments);}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)function getTableAsync(callback) ...{return Jaxer.remote("getTable", arguments, callback);}

    这样在浏览器端的js就可以直接使用了。  
    虽然还有很多问题，最讨厌的就是生成的页面上有全部的clientFramework的源代码，虽然是压缩的，但看着还是很麻烦，估计以后的版本这个是首先要修改的。

    上面的例子可以到这里[http://download.csdn.net/user/luq885/](http://download.csdn.net/user/luq885/)直接下载，就是页面和一个jquery.js。

    再说一下用JAXER服务器运行的方法，到[http://aptana.com/jaxer/download](http://aptana.com/jaxer/download)这里下载一个JAXER的服务器端，附带着Apache服务器，直接解压后运行StartServers.bat

就可以启动，把上面那个页面和jquery.js放到public文件夹下，访问[http://127.0.0.1:8081/test2.html](http://127.0.0.1:8081/test2.html)就可以看到效果。