An example of asp.net using Ajax and Jquery to pass parameters from the foreground to the background and return values

高洛峰
Release: 2017-01-12 14:13:20
Original
1673 people have browsed it

1》Front desk

First you need the Jquer package

<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
下面是     <script type="text/javascript">
        $(function () {
            $(&#39;#txtUserName&#39;).blur(function () {
                var username = $(this).val();
                $.ajax({
                    type: "post",
                    contentType: "application/json",//传值的方式
                    url: "WebAjaxForMe.aspx/GetValueAjax",//WebAjaxForMe.aspx为目标文件,GetValueAjax为目标文件中的方法
                    data: "{username:&#39;" + username + "&#39;}",//username 为想问后台传的参数(这里的参数可有可无)
                    success: function (result) {
                        alert(result.d);//result.d为后台返回的参数
                    }
                })
            })
        })
    </script>
//这里是参数的来源
        <input id="txtUserName" type="text" />
Copy after login

2》Backstage

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

[WebMethod]//方法前边必须添加 [WebMethod]      
  public static string GetValueAjax(string username)//这个方法需要是静态的方法要用到关键字static       
{
            //在这里可以对传进来的参数进行任何操作           
    return username;    
 }
Copy after login

For more related articles on how asp.net uses Ajax and Jquery to pass parameters from the foreground to the background and return values, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template