如何将Ajax调用包含为外部文件?

use*_*681 5 html javascript ajax jquery external

我有一个简单的Ajax调用,当我在HTML文件中的结束体标记之前将其包装在脚本中的文档就绪函数中时,它可以正常工作.但是,当我尝试将调用移动到外部.js文件(不包括脚本标记和文档就绪函数)时,调用不起作用.我尝试在HTML文件的头部和正文中添加外部文件,但没有成功:

<script src="includes_js/login3.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

我在这里没有包含太多代码,因为我不确定什么可能有用.

Tre*_*vor 2

However, when I try to move the call into an external .js file, excluding script tags and the document ready function

尝试将文档就绪函数添加到外部 java 脚本文件中。

$(document).ready(function(){
 alert('worked');
 // ajax call here
});
Run Code Online (Sandbox Code Playgroud)

如果警报运行,则意味着正在加载外部 java 脚本文件。否则,标签中的路径可能有问题<script>