【问题标题】:Load HTML String from AJAX Into Fancybox Programmatically以编程方式将 HTML 字符串从 AJAX 加载到 Fancybox
【发布时间】:2019-06-11 15:12:45
【问题描述】:

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

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

我看了这篇文章,但没有运气: JS: Failed to execute 'getComputedStyle' on 'Window': parameter is not of type 'Element'

我也看过这篇文章: 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);
}
});
});

【问题讨论】:

    标签: jquery ajax fancybox-3


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-31
      • 2020-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多