$.ajax 参数数组本篇打算通过get、post、put、

电脑杂谈  发布时间:2018-01-20 19:04:58  来源:网络整理

ajax data传多个参数_js解析json数组对象_$.ajax 参数数组

本篇打算通过get、post、put、delete四种请求方式分别谈谈基础类型(包括int/string/datetime等)、实体、数组等类型的参数如何传递。

回到顶部

对于取数据,我们使用最多的应该就是get请求了吧。下面通过几个示例看看我们的get请求参数传递。

[HttpGet]
public string GetAllChargingData(int id, string name)
{
    return "ChargingData" + id;
}
$.ajax({
        type: "get",
        url: "http://localhost:27221/api/Charging/GetAllChargingData",
        data: { id: 1, name: "Jim", bir: "1988-09-11"},
        success: function (data, status) {
            if (status == "success") {
                $("#div_test").html(data);
            }
        }
    });

参数截图效果

这里写图片描述

这是get请求最基础的参数传递方式,没什么特别好说的。

如果我们在get请求时想将实体对象做参数直接传递到后台,是否可行呢?我们来看看。

public class TB_CHARGING
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        public string ID { get; set; }

        /// <summary>
        /// 充电设备名称
        /// </summary>
        public string NAME { get; set; }

        /// <summary>
        /// 充电设备描述
        /// </summary>
        public string DES { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CREATETIME { get; set; }
    }
[HttpGet]
public string GetByModel(TB_CHARGING oData)
{
     return "ChargingData" + oData.ID;
}
$.ajax({
        type: "get",
        url: "http://localhost:27221/api/Charging/GetByModel",
        contentType: "application/json",
        data: { ID: "1", NAME: "Jim", CREATETIME: "1988-09-11" },
        success: function (data, status) {
            if (status == "success") {
                $("#div_test").html(data);
            }
        }
    });


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-61568-1.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 田馥甄
      田馥甄

      高喊着防杀伤性武器入侵伊拉克

    • 齐旭东
      齐旭东

      国家的概念除了在生死存亡之时格外强烈外

    • 夏书霞
      夏书霞

      赚了

    热点图片
    拼命载入中...