2018年6月2日 星期六

vb web form 使用ajax傳回到指定網頁函式內

網頁--.aspx

       $(document).ready(function () {
            $('#SendMail').click(function () {
                debugger;
                var str = $("#BodyStr").html();
                var result = $.ajax({
                    type: "POST",
                    url: "VBAjax_SendMail.aspx/TestAjax",
                    data: '{ strBody: "' + str + '" }',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: succeeded,
                    failure: function (msg) {
                        alert(msg);
                    },
                    error: function (xhr, err) {
                        alert(err);
                    }
                });
            });

            //            //'{ strBody: "1833", qty: "13", lblType: "1" }',
        })

        function succeeded(msg) {
            debugger;
            alert(msg.d);
        }



-.aspx.vb
Imports System.Web.Services

   
    Public Shared Function TestAjax(strBody As String) As String

        Dim selectedProduct As String = String.Format("{0}", strBody)

        HttpContext.Current.Session("test") = selectedProduct

        Return HttpContext.Current.Session("test").ToString()

    End Function














沒有留言:

張貼留言