Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在C#中使用toaster显示ajax返回的消息?_Javascript_C#_Jquery_Ajax_Popup - Fatal编程技术网

Javascript 如何在C#中使用toaster显示ajax返回的消息?

Javascript 如何在C#中使用toaster显示ajax返回的消息?,javascript,c#,jquery,ajax,popup,Javascript,C#,Jquery,Ajax,Popup,作为C#的初学者,我正在努力展示祝酒词。我有一个aspx页面,我必须在点击按钮后显示toast消息。我为toast消息添加了一个隐藏字段: <button class="BtnCart" onclick="return addToCart(event)" title="Add"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Add to Cart </button> <asp:H

作为C#的初学者,我正在努力展示祝酒词。我有一个aspx页面,我必须在点击按钮后显示toast消息。我为toast消息添加了一个隐藏字段:

<button class="BtnCart" onclick="return addToCart(event)" title="Add"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Add to Cart </button>
<asp:HiddenField runat="server" Value="0"/>
添加到购物车
我有一个ajax调用,它返回我需要在toast中显示的消息。我已经开始做下面的事情了,请帮帮我

<script src="scripts/toastr.min.js" type="text/javascript"></script>
   <script type="text/javascript">
        $(document).ready(function () {
            $(".showToast").click(function () {
            });
        });
        function addToCart(event) {
            console.log(event.target);
            var Id = $(event.target).parent().find('.Id').val();
            var qty = $(event.target).parents('#searchbottom').find('#qty').val();

            console.log(Id);
            console.log(qty);
            var item = {};
            item.Id = Id;
            item.quantity = qty;        

            $.ajax({
                type: 'POST',
                url: '/api/shop/Add',
                data: JSON.stringify(item),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json'
            }).done(log);

            return false;
        }
        function log(data) {
            console.log(data);
           // alert(data.message);            
        }       

        function pageLoad(sender, args) {
            if (args.get_isPartialLoad()) {

                toastr.options = {
                    "closeButton": false,
                    "debug": false,
                    "newestOnTop": false,
                    "progressBar": false,
                    "positionClass": "toast",
                    "preventDuplicates": false,
                    "onclick": null,
                    "showDuration": "10",
                    "hideDuration": "10",
                    "timeOut": "5000",
                    "extendedTimeOut": "10",
                    "showEasing": "swing",
                    "hideEasing": "linear",
                    "showMethod": "fadeIn",
                    "hideMethod": "fadeOut",
                    'body-output-type': 'trustedHtml'
                }
                toastr.success(data.value); 

$(文档).ready(函数(){
$(“.showtoos”)。单击(函数(){
});
});
函数addToCart(事件){
console.log(event.target);
var Id=$(event.target.parent().find('.Id').val();
var qty=$(event.target).parents('#searchbottom').find('#qty').val();
console.log(Id);
控制台日志(数量);
var item={};
项目Id=Id;
项目数量=数量;
$.ajax({
键入:“POST”,
url:“/api/shop/Add”,
数据:JSON.stringify(项目),
contentType:'application/json;charset=utf-8',
数据类型:“json”
}).完成(日志);
返回false;
}
功能日志(数据){
控制台日志(数据);
//警报(数据、消息);
}       
函数页面加载(发送方,参数){
if(args.get_isPartialLoad()){
toastr.options={
“closeButton”:false,
“调试”:错误,
“newestOnTop”:错误,
“progressBar”:错误,
“positionClass”:“toast”,
“防止重复”:错误,
“onclick”:空,
“showDuration”:“10”,
“隐藏”:“10”,
“超时”:“5000”,
“extendedTimeOut”:“10”,
“挥杆”:“挥杆”,
“隐藏”:“线性”,
“showMethod”:“fadeIn”,
“隐藏法”:“淡出法”,
“正文输出类型”:“trustedHtml”
}
成功(数据值);

像这样更改标签按钮:

添加到购物车