Ajax. Net Usage Basics

Source: Internet
Author: User

Ajaxpro. Utility. registertypeforajax (typeof (resin ));
Register the current page using the above method, and add the following two sentences to the page after running
<SCRIPT type = "text/JavaScript" src = "/ajaxdemo/ajaxpro/CORE. ashx"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "/ajaxdemo/ajaxpro/ajaxdemo. resin, ajaxdemo. ashx"> </SCRIPT>

<Script language = "JavaScript">
VaR response = sample. serversideadd (100,99 );
Alert (response. value );
</SCRIPT>

Added client callable Methods
Public int serversideadd (INT firstnumber, int secondnumber)
{
Return firstnumber + secondnumber;
}

Client call
<Form ID = "form1" method = "Post" runat = "server">
<Script language = "JavaScript">
VaR response = ajaxdemo. Resin. serversideadd (100,99 );
Alert (response. value );
</SCRIPT>
</Form>

At the same time, you can change the following to return a response object and handle program exceptions.
<Form ID = "form1" method = "Post" runat = "server">
<Script language = "JavaScript">
// Var response = ajaxdemo. Resin. serversideadd (100,99 );
// Alert (response. value );
Ajaxdemo. Resin. serversideadd (100,99, serversideadd_callback );
Function serversideadd_callback (response ){
If (response. Error! = NULL ){
Alert (response. Error );
Return;
}
Alert (response. value );
}

</SCRIPT>
</Form>

Example of dataset Processing
Server
Public dataset getdataset ()
{
// Sqlhelper. executereader (configurationsettings. receivettings ["connstring"], "gethostitallistbypymandgroupid", querycode, groupid );

Dataset myds = new dataset ();
Myds = sqlhelper. executedataset (configurationsettings. deleettings ["connstring"], commandtype. Text, "select top 10 ypm, GG, CD, zxdw from zy_sys2_ypzdk ");
Return myds;
}
Client
<Script language = "JavaScript">
Ajaxdemo. Resin. getdataset (getdataset_callback );
Function getdataset_callback (response ){
VaR DS = response. value;
If (Ds! = NULL & typeof (DS) = "object" & Ds. tables! = NULL ){
VaR S = new array ();
S [S. Length] = "<Table border = 1> ";
For (VAR I = 0; I <Ds. Tables [0]. Rows. length; I ++ ){
S [S. Length] = "<tr> ";
S [S. Length] = "<TD>" + Ds. Tables [0]. Rows [I]. ypm + "</TD> ";
S [S. Length] = "<TD>" + Ds. Tables [0]. Rows [I]. gg + "</TD> ";
S [S. Length] = "</tr> ";
}
S [S. Length] = "</table> ";
Alert (S. Join (""));
}
Else
{
Alert ("error. [3001]" + response. Error );
}
}
</SCRIPT>

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.