Ajaxprc is a fast and simple JavaScript remote method call. It allows you to use JavaScript to call the server method. It is based on the JSON data protocol, open-source authorization (lgpl), and can be called synchronously and asynchronously.
With ajaxrpc, you can develop web programs just like developing traditional C/S programs, making web development simpler and more efficient.
Supports server languages: Java,. net, and PHP.
Supports browsers such as IE, Firefox, opera, Safari, and chrome.
The following is a brief demonstration of the usage method. For details, visit the website.
First, we define a class and static method on the server: public class test {
Public static string sayhello (string name ){
Return "hello," + name;
}
}
Note: it must be a public static method.
Then, we use the ajaxrpc client to call the server method.
Note: when calling the RPC method, if the callback function is not passed, the call is synchronous; if the callback function is passed, the call is asynchronous.
Synchronous call <SCRIPT type = "text/JavaScript">
......
Try {
VaR OBJ = test. sayhello ('World! ');
......
} Catch (e ){
// E. Error error code
// E. Message error description
}
......
</SCRIPT>
Do not pass the callback function. Use try... Catch to handle errors. In synchronous call mode, if a network error or business logic error occurs, an exception is thrown.
Asynchronous call code
<SCRIPT type = "text/JavaScript">
......
Test. sayhello ('World! ',
Function (OBJ) {// success callback function
......
},
Function (error, message) {// fail callback function
}
);
......
</SCRIPT>
Pass the callback function as a parameter. If there is only one callback function, a successful callback function is used by default.
This data interaction method is very convenient and efficient. In fact, there are already many web-based RPC projects, such as DWR (Java) and ajaxpro (. net), xajax (PHP), but they all have more or less disadvantages.
For example, DWR has its own data protocol. The consequence is that the volume of data transmitted is more than two times larger than that of JSON.
Ajaxrpc is an Ajax project based on the JSON data protocol. It has the advantages of being small, simple, easy to use, and supports Java \. the net \ PHP platform is based on the lgpl open source protocol and can be easily applied to projects.
Project Website: http://ajaxrpc.com
Http://ajaxrpc.com/cn/index.html