ASP.NET透過jQuery Ajax不斷更新呼叫WebMethod存取套用jQuery Sortable效果的DIV內項目順序列表

 






首先先有辦法在drag放置完取得順序列表

See the Pen jQuery Sortable Test by Jacob (@dryjoker) on CodePen.





在前台stop方法裏頭包覆傳遞order list的ajax呼叫

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
$.ajax({
    type: "POST",
    url: "../SubWin/PatentDeDup.aspx/SaveOrderList",
    contentType: "application/json;charset=utf-8",
    data: '{order_list: "' + sort_id + '" }',
    dataType: "json",
    success: function (data) {
        if (data.d == "success") {
            console.log("save order list successfully");
        }
        else {
            //alert(data.d);
            console.log("save order list not return success");
            console.log(data.d);
        }
    },
    error: function (result) {
        alert("API Error");
    }
});




後端aspx.cs

1
2
3
4
5
6
7
8
    [System.Web.Services.WebMethod(EnableSession = true)]
    public static string SaveOrderList(string order_list)
    {
        string result = "success";
        System.Web.HttpContext.Current.Session["OrderCountryList"] = order_list;

        return result;
    }

將方法改為static(類別層級不需new出實體才可調用)
並在上方加入WebMethod的修飾,此外這裡由於要存入session因此turn true







Ref:

https://dotblogs.com.tw/justforgood/2016/10/21/172354
https://johnny.github.io/jquery-sortable/

















留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題