Today, I occasionally found an article titled "client-side JavaScript Functions call server-side methods"

Source: Internet
Author: User

This method is really simple, but it may not be appropriate when Ajax is used. I think, let's first look at how to implement it:
<Script language = "JavaScript">
Function AA ()
{
VaR S = "<% = binddata () %> ";
Alert (s );
}
</SCRIPT>
The above is the method called:
The following method is used on the server:
Protected string binddata ()
{
Try
{
Sqlconnection con = new sqlconnection ("Server =.; uid = sa; Pwd = sa; database = test ");
Sqlcommand COM = new sqlcommand ("Update customer set Pwd = 'newpassword' where customerid = 22", con );
Con. open ();
Com. executenonquery ();
Con. Close ();
Return "modification successful ";
}
Catch
{
Return "failed to modify ";
}
}
This is a call, and it seems like an Ajax method at first glance. Actually, it is not. This method does not conform to the Ajax principle we usually call, when loading the page for the first time, it has completed the binddata () and saved the returned value to the variable S defined in Js, when we set out this JavaScript function, we will do var S = "<% = binddata () %>"; until now, I have found that only Ajax is used. dll can do a better job of requesting data on demand. I don't know if I can use XMLHTTP, but I know what I want to write. Code Too many, very cumbersome. This problem has been studied for a long time and has not been found using Ajax. dll ~~~~~~~~

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.