zoukankan      html  css  js  c++  java
  • 从零学习wcf(一)

    开发环境VS2008,新建网站网站,添加启用Ajax的wcf服务如下图

    打开App_Code下的CS文件,添加如下方法

    在浏览器中运行新增的AjaxService.svc如下图

    在浏览器地址栏中加上/js 继续运行得到一个js文件包存到网站中,

    在页面中添加

        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Path="~/WcfService/AjaxWcf.js" />
            </Scripts>
        </asp:ScriptManager>

    调用方法一

        javascript调用

        window.onlaod=function(){

         AjaxService.Getvalue("东明", "21", onSuccess);

      }

     function onSuccess(res) {
                alert(res);
            }   

    调用方法二

        jquery调用

               $.ajax({
                    type: 'POST',
                    url: 'WcfService/AjaxService.svc/GetString',
                    contentType: 'text/json',
                    data: '',
                    success: function(result) {
                        alert(result.d);
                    }
                });

                $.ajax({
                    type: 'post',
                    contentType: 'text/json',
                    url: 'WcfService/AjaxService.svc/Getvalue',
                    data: '{"name":"小明","age":"10"}',
                    success: function(result) {
                        alert(result.d);
                    }
                });

        调用成功!.....

  • 相关阅读:
    js location.href ,location.replace, location.reload
    //js date对象常用方法
    js Math对象常用方法
    n sum
    two sum
    树:树中两个节点的最低公共祖先
    C++11:智能指针与lambda表达式
    回溯: 0-1背包
    动态库的soname实验
    DNS介绍与安装使用
  • 原文地址:https://www.cnblogs.com/ajun/p/2517608.html
Copyright © 2011-2022 走看看