jquery - 以编程方式将 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);
}
});
});
解决方案
如果您希望显示 HTML 内容,则内容类型应为html
,例如,更改为type: 'html'
.
推荐阅读
- java - 从 Java 运行 Python 脚本并传递用户输入
- javascript - 如何重定向到外部 MP4 文件链接
- spring-boot - 如何使用 Spring Boot Web 客户端为内容类型 application/x-www-form-urlencoded 的表单数据发布请求
- javascript - HTML 页面上的简单嵌入式 VLC 插件,从特定时间开始
- python - 使用 Jenkins 在 Apache HTTPD 上部署 Python 代码
- java - 在 AWS Java Lambda 中找不到类异常
- mysql - 有没有办法使用 liquibase-maven-plugin 实际执行 DDL 更新?
- python - 继承先前对象属性的新对象
- sonos - 未调用编程无线电 GET /上下文端点
- c# - 简化道路系统的碰撞网格?