[英]How include files just when need them?
I am using Laravel, sending Ajax requests to server. 我正在使用Laravel,将Ajax请求发送到服务器。 But I don't need some libraries like DropzoneJS (a library for Ajax uploading ), some images, some functions before some Ajax requests.
但是在某些Ajax请求之前,我不需要像DropzoneJS (一个用于Ajax上传的库)之类的库,一些图像,一些功能。
Is there any way to include them after some actions? 经过一些动作后有什么方法可以包含它们吗?
for example include a library when an element clicked 例如,当元素单击时包括一个库
Is there any library to do this job? 有图书馆可以做这项工作吗?
If you need to pre-load required stuff you can use requirejs
for that purpose. 如果您需要预加载必需的内容,可以为此使用
requirejs
。
Keep in mind that using it will "hold" your code until all the requirements are for-filled. 请记住,使用它会“保留”您的代码,直到满足所有要求为止。
If you need to do some stuff after the AJAX is completed you can use promises or callbacks to capture the response and do what ever you need to do. 如果您需要在AJAX完成后做一些事情,则可以使用Promise或回调来捕获响应并执行所需的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.