ASP. NET uses Ajax and jquery to pass parameters back to the foreground and return an instance of the value

Source: Internet
Author: User
1 "Front desk

First, you need a Jquer package.

<script src= "Js/jquery-1.9.1.js" type= "Text/javascript" ></script> below is     <script type= "text/ JavaScript >        $ (function () {            $ (' #txtUserName '). blur (function () {                var username = $ (this). Val ();                $.ajax ({                    type: "Post",                    ContentType: "Application/json",//value-in-A-way                    URL: "Webajaxforme.aspx/getvalueajax", Webajaxforme.aspx is the target file, Getvalueajax is the method data in the target file                    : "{username: '" + Username + "'}",//username                    success:function (Result) {                        alert (RESULT.D),//result.d returned as a background                    }                }) for the background pass parameter (the parameter is optional)            })        })    </script>//here is the source of the parameter        <input id= "txtUserName" type= "text"/>

2 "Backstage

In the background, you first add the using System.Web.Services;

[webmethod]//method must be added in front of [WebMethod] public static string Getvalueajax (string user     Name)//This method needs to be static method to use the keyword static {//here can be passed in the parameters of any operation return username; }
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.