javascript:javascript
function get(url, success) { $.ajax({ type: "Get", url: url, data: {}, contentType: "application/json", dataType: "json", success: success || function (res) { }, error: function () { alert("ajax error"); } }); } //调用 get("/api/sample", function (res) { console.log(res); }); //使用箭头函数简化 get("/api/sample", (res) => { console.log(res); });
C#java
public static void Get(string url, Action<string> success) { WebClient client = new WebClient(); string result = client.DownloadString(url); success(result); } //调用 Get("/api/sample", delegate (string res) { Console.WriteLine(res); }); //使用lambda表达式简化 Get("/api/sample", (res)=>{ Console.WriteLine(res); });
还要说总结什么吗?ajax