zoukankan      html  css  js  c++  java
  • jquery调用asp.net的WebService

    asmx.cs

    using System.Web.Script.Services;



    [System.Web.Script.Services.ScriptService]
    public class test : System.Web.Services.WebService

    {

    [ScriptMethod(UseHttpGet = true)]

    public void testMethod(int id)
    {
    }

    }

    js

    $.ajax({
    url: 'test.asmx/testMethod',
    dataType: "json",
    data: "id=2",
    beforeSend: function(x) {
    x.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    },
    success: function(json) {
    var o = eval("(" + json.d + ")");
    callBack(o);
    }
    });

    或者向下面这样直接使用也行,原因暂时不明

            $.ajax({
                type: 
    "POST",
                url: 
    "/test.asmx/testMethod",
                data: {
                    htmlStr: 
    "<font color='red'>你好</font>",
                    Co: 
    877,
                    Tablename: 
    "table_2",
                    buttonId: 
    96
                },
                success: 
    function () {
                    alert(
    "success");
                },
                error: 
    function () {
                }
            });
  • 相关阅读:
    P2082 区间覆盖(加强版)
    Java基础
    @import
    POST方式"Content-type"是"application/x-www-form-urlencoded 的请求遇到的问题
    VBox 安装 macOS 10.12
    对称加密和分组加密中的四种模式(ECB、CBC、CFB、OFB)
    window.location 属性
    post get 区别
    vue 生命周期
    记事本
  • 原文地址:https://www.cnblogs.com/timy/p/2017454.html
Copyright © 2011-2022 走看看