DevExtreme 学习应用[2]

DevExtreme 学习应用[2]

调用WebService数据

1那么首先建立WebService

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebService
{
    /// <summary>
    /// WebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    //以上这句要有 不然会报错  因为手机开发一般是要以Json形式获取数据
public class WebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

2HTML

  <div data-bind="dxCommand: {
title: 'Search', placeholder: 'Search...',
    location: 'create', icon: 'btn',value:'button', action: find
}"></div>

3JavaScript  该JS是以Jquery的形式调用的。所以只要做过Jquery的都比较清楚

Application1.ProductDetial = function (params) {

    var viewModel = {
        find: function () {
            $.ajax({
                url: 'http://localhost:5421/WebService/WebService.asmx/HelloWorld',
                data: {},
                //data:{} 因为我们在这里测试的使用的HelloWord 方法是无参的。所以这里为空。要是有参数的方法  如参数为Name:data:{name:'李四'}  备注:这里的参数名 最好和服务端的参数名称一致
contentType:
"application/json", dataType: "json", type: "POST", success: function (result) { alert(result.d); }, error: function (xml, status) { alert(status); } }); } }; return viewModel; };

 总结:DevExtreme 开发中调试通了 调用C# WebService的方法。

原文地址:https://www.cnblogs.com/w2011/p/3423219.html