首页 > 解决方案 > 以编程方式将 HTML 字符串从 AJAX 加载到 Fancybox

问题描述

我试图在 Fancybox 3 中以编程方式显示 HTML 字符串,但出现以下错误:'无法在'Window'上执行'getComputedStyle':参数 1 不是'Element'类型。

在此处输入图像描述

我确实尝试将类型更改为“内联”并使用 href,但没有运气。我还尝试在没有额外 GetHTML 变量的情况下将内容更改为数据。

我看了这篇文章,但没有运气: JS:无法在“窗口”上执行“getComputedStyle”:参数不是“元素”类型

我还看了这篇文章: Loading dynamic AJAX content into Fancybox

$('.LinkFancybox').on('click', function () {
  var CategoryID = $(this).attr("id");
  var UserID = "<%=CurrentUserId%>";
  var CompanyID = "<%=CompanyID%>";
  var CurrentCustomerCode = "<%=CurrentCustomerCode%>";

if (CurrentCustomerCode == "") {
  CurrentCustomerCode = "000-000";
}

var APIURL = $.fn.GetBaseURL() + 'DesktopModules/DNNCommon/API/Store/GetProductsForPubCat?CategoryId=' + CategoryID + '&UserID=' + UserID + '&CompanyID=' + CompanyID;

$.ajax({
  type: "GET",
  async: true,
  url: APIURL,
  datatype: "json",
  success: function (data) {
  var GetHTML = data;
  $.fancybox.open({
  type: 'ajax',
  width: 800,
  height: 800,
  autoSize: false,                         
  content: GetHTML
});
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.responseText);
}
});
});

标签: jqueryajaxfancybox-3

解决方案


如果您希望显示 HTML 内容,则内容类型应为html,例如,更改为type: 'html'.


推荐阅读