Ajaxrpc: javascript directly calls the server Method

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.