如果我在外部 JavaScript 文件中有以下代码;如果我调用的PHP文件位于同一目录中,我是否必须添加“../directory/filename.php”? php 脚本没有运行,我已经在另一个线程中完整发布了该脚本,但我认为它可能与我的 $.ajax 调用中的“URL”有关。
$.ajax({
type: 'POST',
url: '../script/mail.php',
data: {fname:firstName, lname:lastName, email:emailVal, comment:comments, fileName:fileName},
success: function(){
$('form').each(function() {
this.reset();
});
}
});
上一个问题: PHP Mailer script not completing after ajax call and form submit
最佳答案
JavaScript 程序(嵌入网页中)中的 URL 与页面的 URL 相关。
if the PHP file I'm calling is located in the same directory, do I have to add "../directory/filename.php"?
如果filename.php
与HTML文档位于同一目录中,则不需要,您只需执行filename.php
即可。
如果filename.php
与外部JS文件在同一目录中,那么……也许吧,但你需要查看HTML文档在哪里,而不是JS文件。
关于javascript - AJAX 调用源自哪个目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21631865/