加载动态 html jQuery 更改 GET 脚本路径
Load dynamic html jQuery changing GET script path
我正在尝试从 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" 中的 jQuery 和 $(' #MyDiv').html(...) 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", that's incorrect, the correct is "http://localhost:8080/NuevoERP/includes/js/gestion/productos/detailProductoServicio.js 加载文件“
我正在将 Apache 与 Lumen Framework 一起使用,我的应用程序位于我的 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 ^(.*)/$ / [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,没说什么就创建了,这是修改网络浏览器的请求以获取 javascript 文件
我正在尝试从 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" 中的 jQuery 和 $(' #MyDiv').html(...) 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", that's incorrect, the correct is "http://localhost:8080/NuevoERP/includes/js/gestion/productos/detailProductoServicio.js 加载文件“
我正在将 Apache 与 Lumen Framework 一起使用,我的应用程序位于我的 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 ^(.*)/$ / [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,没说什么就创建了,这是修改网络浏览器的请求以获取 javascript 文件