javascript - 加载动态 html jQuery 更改 GET 脚本路径
问题描述
我正在尝试从 URL 动态加载 HTML。我使用这段代码:
LoadingSpinner.open();
$.ajax({
url: '/Views/MyView',
data: data,
dataType: 'html',
type: 'GET',
success: function(response){
//This line trigger the error
$('#MyDiv').html(response.replaceAll('\n', ''));
LoadingSpinner.close();
},
error: function(){
LoadingSpinner.close();
ModalService.abrirModalError('Error de conexion', 'Ha ocurrido un error obteniendo la página');
}
});
当我确实单击一个元素时,我通过 GET MyView 请求,这工作正常,但是当我使用带有 $('#MyDiv').html(...) 的“MyDiv”中的 jQuery 将这个视图呈现到我的页面时该 HTML 中的脚本标记失败。包含我的脚本标签的 HTML 是这样的:
<script src="/NuevoERP/includes/js/gestion/productos/detailFamilia.js" type="text/javascript"></script>
<h2>Detalle de la familia {{$familia->desc_nombre}}</h2>
<div class="col-lg-12 m-t-5">
<div class="col-lg-3">
<label>Categoria de la familia: <span class="fontNormal">{{$familia->categoriaFamilia->desc_nombre}}</span></label>
<label>Referencia: <span class="fontNormal">{{$familia->code_referencia}}</span></label>
<label>Nombre: <span class="fontNormal">{{$familia->desc_nombre}}</span></label>
<?php if ($familia->familiaPadre != null) : ?>
<label>Familia padre: <span class="fontNormal">{{$familia->familiaPadre->desc_nombre}}</span></label>
<?php endif;?>
</div>
</div>
我正在尝试使用 src="/NuevoERP/includes/js/gestion/productos/detailFamilia.js" 包含 javascript 文件,但浏览器控制台显示我正在尝试从“ http://localhost:8080加载文件/NuevoERP/http://localhost:8080/NuevoERP/includes/js/gestion/productos/detailProductoServicio.js ”,不对,正确的是“ http://localhost:8080/NuevoERP/includes/js/gestion/productos /detailProductoServicio.js "
我正在使用带有 Lumen 框架的 Apache,我的应用程序位于我的 DocumentRoot 的其他路径中,我正在使用别名,这就是我的 apache.conf:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:8080
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:8080>
DocumentRoot "/Volumes/HDD/NetBeansProjects/AntiguoERP/Desarrollo/ERP"
ServerName localhost
Alias /NuevoERP "/Volumes/HDD/NetBeansProjects/BaymaSalt/ERPBaymaSalt/public"
<Directory "/Volumes/HDD/NetBeansProjects/BaymaSalt/ERPBaymaSalt/public">
AllowOverride All
</Directory>
</VirtualHost>
我的 Lumen index.php("/Volumes/HDD/NetBeansProjects/BaymaSalt/ERPBaymaSalt/public") 的 .htaccess 是:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /NuevoERP/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
我不能使用两个不同的 VirtualHost,我需要一个带有我的根路径 ( http://localhost:8080 ) 和 php 5.0 的主机和我的 Alias /NuevoERP 和 php 7.0
解决方案
代码是正确的,问题是合作伙伴创建了一个 AJAX 请求拦截器并在运行时修改了 URL,没有说什么就创建了它,这是在修改 Web 浏览器的请求以获取 javascript 文件
推荐阅读
- git - 创建仓库的克隆/副本并同步两个仓库
- docker - 在带有 PostgresSql 数据库的 docker 容器中运行简单的 Kotlin Ktor 应用程序
- webpack - webpack 样式、ts 和 css 加载器应该只在当前文件夹内构建文件
- docker - 如何获取单个应用程序的 Docker 容器配置?
- python - 神经网络实际返回三类 2
- c - 使用 Int 和浮点值更新 char 数组,而不使用 sprintf?
- web-services - 需要帮助为分布式系统构建正常运行时间仪表板
- elixir - 你如何抑制来自 Prometheus 库的警告?
- tsql - 在字段的起始位置替换字符串
- sql - JSONB 使用包含运算符连接