• jquery调用webservice


    1.给webserver加 [System.Web.Script.Services.ScriptService]标签
    如:
    Code

    2.js
       $(
            
    function()
            {
                
    function WebService(url,pars,callback)
                { 
                    $.ajax
                    ({ 
                        async :
    false,
                        data:pars, 
                        url: url, 
                        type: 
    "POST"
                        contentType: 
    "application/json;utf-8"
                        dataType:
    'json'
                        cache: 
    false
                        success: 
    function(json){ 
                            callback(json);
                        },
                        beforeSend:
    function(xml)
                        { 
                            
    if(!pars) 
                            {
                                xml.setRequestHeader(
    "Content-Type""application/json;utf-8")
                            } 
                        },
                        error:
    function(xml,status)
                        { 
                            
    if(status=='error')
                            { 
                                
    try
                                { 
                                    
    var json = eval('(' + xml.responseText + ')'); 
                                    alert(
    'Err:' + json.Message+'\n'+json.StackTrace); 
                                }
                                
    catch(e)
                                {} 
                            }
                            
    else
                            { 
                                alert(
    'Err:' + status); 
                            } 
                        }                           
                    });
                }
                
                $(
    "#btnLogin").click
                (
                    
    function()
                    {
                       
    var n,p,r;
                        n
    =$("#txtUsername").val();
                        p
    =$("#txtPassword").val();
                        
    if(n.length==0 || p.length==0)
                        {
                            alert(
    "Please input user name and password.");
                            $(
    "#txtUsername")[0].focus();
                            
    if(n.length>0)
                                $(
    "#txtPassword")[0].focus();
                             
    return false;
                        }
                        WebService(
                            
    "user.asmx/Login",
                            
    "{name:'" + n + "',pwd:'" + p + "'}",
                            
    function(jason)
                            {
                                
    if(!jason)
                                {
                                    alert(
    "User name or password error,please retry.");
                                    $(
    "#txtPassword")[0].focus();
                                    r 
    = false;
                                }
                                
    else
                                {
                                    r 
    = true;
                                }
                            }
                        );
                        
    if(r)
                            window.location.href
    ="/MainForm.aspx";
                        
    return false;
                    }            
                )
            }
        )
  • 相关阅读:
    Spring 由哪些模块组成?
    spring 支持哪些 ORM 框架 ?
    @Autowired 注解有什么用?
    spring JDBC API 中存在哪些类?
    有哪些类型的通知(Advice)?
    @Component, @Controller, @Repository, @Service 有何区别?
    @Qualifier 注解有什么用?
    什么是 Aspect?
    什么是通知(Advice)?
    spring bean 容器的生命周期是什么样的?
  • 原文地址:https://www.cnblogs.com/zyip/p/1561779.html
Copyright © 2020-2023  润新知