我有一个名为filesUploadScript.js
的文件,其中定义了以下代码:
function filesUploadScript() {
(function () {
... Load Resumable and do some upload work ...
})
})
我正在这样导入app.js中的文件:
require('../js/filesUploadScript');
在查看源代码时,我能够看到文件的内容。
我的webpack配置文件如下:
var Encore = require('@symfony/webpack-encore');
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Add 1 entry for each "page" of your app
* (including one that's included on every page - e.g. "app")
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry('app', './assets/js/app.js')
在某个时候,我正在使用AJAX加载模式和一些html内容,我需要在其中加载和使用filesUploadScript()
当我加载ajax和响应时,由于出现错误Uncaught ReferenceError: filesUploadScript is not defined
,我无法使该功能正常工作。
ajax调用非常简单,我将其记录下来以供参考:
$.ajax({
url: _el.data('content'),
success: function (response) {
try {
modalContent.html(response);
modal.modal('show');
} catch (err) {
modalContent.html('An error has occurred: ' + err.message);
modal.modal('show');
}
},
})
我的上传器html文件也类似这样
<div class="row">
Content of the uploader html
</div>
<script>filesUploadScript();</script>
现在这引起两个问题:
由于filesUploadScript()
存在于
源代码,但仍然出现错误。 (如果我要导入
文件作为独立脚本起作用)
我如何使用该函数对html的响应来自 阿贾克斯打电话吗?基本上是在响应中加载了JS。