popover 在 ajax 上显示“[object Object]”

问题描述 投票:0回答:1

enter image description here

如图所示,我的引导弹出窗口触发并显示“[object Object]”,而不是我从数据库检索的数据。我将日志放在 js ajax 代码上,发现我检索了数据,但无法在弹出窗口上显示它。可能是什么问题?

          <script >
    
      $(document).ready(function () {
            $('#tog').on('click', function (e) {
                e.preventDefault();
            });
            console.log("Popover initialization started.");
            $('[data-toggle="popover"]').popover({
                placement: 'right',
                title: 'Update Changes',
                trigger: 'hover',
                html: true,
    
                content: function () {
                    console.log("Popover content loading started.");
                    var reasonCode = $(this).closest('tr').find('.reason_code').text();
                    console.log("Reason code:", reasonCode);
                    return $.ajax({
    
                        type: 'POST',
                        url: 'CCA_Crups_Reason.aspx/GetPopoverContent',
                        data: JSON.stringify({ reasonCode: reasonCode }),
                        contentType: 'application/json; charset=utf-8',
                        dataType: 'json',
                        success: function (response) {
                            //Extract the data from the response
                            var data = response.d;
    
                            console.log(data)
    
                            return data
    
                        },
                        error: function (xhr, status, error) {
                            console.error(xhr.responseText);
                            console.error("Ajax request failed:", xhr.responseText);
                        }
                    });
                }
            });
    
            
      });
    
    
        
    
    </script>

});
javascript .net asp.net-ajax popover bootstrap-popover
1个回答
0
投票

您尝试显示的数据不是字符串。

[object Object]
是 Javascript 从对象到字符串的默认转换。

您可以通过将日志更新为

console.log(typeof data)
来仔细检查函数响应数据的数据类型,这将帮助您适当地格式化数据。

© www.soinside.com 2019 - 2024. All rights reserved.