A preliminary understanding of asynchronous JavaScript and XML (AJAX)

Source: Internet
Author: User
Tags add object call back end functions integer net wrapper
Ajax|javascript|xml

Download Ajax.dll http://ajax.schwarz-interactive.de/csharpsample/default.aspx

The first example suggests a reference to its quickguide, it feels good
and quote here.
AJAX. Net Wrapper Quick Usage Guide
Karl seguin-http://www.openmymind.net/-Copyright 2005

(View Ajaxguide.doc For more detailed information)


Step 1-
Create a reference to the Ajax.dll file

Step 2-set up the HttpHandler
In the web.config, set up the HttpHandler, like:






...


Step 3-
In the Page_Load event, call the following function:

' VB.net
Public Class Index
Inherits System.Web.UI.Page

Private Sub Page_Load (sender as Object, e as EventArgs) Handles MyBase.Load
Ajax.Utility.RegisterTypeForAjax (GetType (Index))
'...
End Sub
'...
End Class


C#
public class index:system.web.ui.page{
private void Page_Load (object sender, EventArgs e) {
Ajax.Utility.RegisterTypeForAjax (typeof (Index));
//...
}
//...
}

Step 4-
In the codebehind of your page, add functions (like your normally would) that you ' d like to be able to asynchrounsly called  by Client-side scripting. Mark functions with the Ajax.javascriptmethodattribute ():

C#
[Ajax.ajaxmethod ()]
public int Serversideadd (int firstnumber, int secondnumber)
{
return firstnumber + secondnumber;
}

' VB.net
_
Public Function Serversideadd (ByVal firstnumber As Integer, ByVal secondnumber As Integer) As Integer
return Firstnumber + Secondnumber
End Function

The wrapper would automatically create a JavaScript function named "Serversideadd" which accepts to parameters. When called, this server-side function is called and the result returned.


Step 5-
Using JavaScript, you can invote the Serversideadd function like your would any other JavaScript function.  You can call it using the two parameters, or optionally pass a call back function. The name of the "function is", by default, ., such as Index.servers Ideadd:

Alertindex.serversideadd (100,99));

OR

Index.serversideadd (100,99, serversideadd_callback);

function Serversideadd_callback (response) {
alert (Response.value);
}

The response exposes three properties, error, value and request.


Note This can return to more complex objects the simple types.


The demo For additional information:
Http://ajax.schwarz-interactive.de/csharpsample/default.aspx

It's the first example you've ever modeled, and hopefully more people will be involved.



Related Article

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.