繁体   English   中英

无法访问PHP文件

[英]Not able to access php file

我已经重组了目录结构,并且未使用/调用我的php文件。 好像我无法访问它。 在此之前,我的功能和php文件已按预期工作,并且我的文件许可权得到了整理,因此有人可以将我引向正确的方向吗?

目录如下:

public_html(folder)
  - javascript(folder)
    - main(folder)
      - userManagement.js => The `tryEmail` function is in here.
  - php(folder)
    - users-profs(folder)
      - tryEmail.php
  - index.html

编码:

 function tryEmail(email)
    {
        console.log("function:tryEmail, param: " + email);
        return function()
        {
            $.post("../../php/users-profs/tryEmail.php",
            {
                email:email
            },
            function(data)
            {
                console.log("function:tryEmail-post, data: " + data);
                if(data == "valid")
                    return true;
                else
                    return false;
            });
        }
    }

URL ../../php/users-profs/tryEmail.php将相对于用户当前的URL而不是.js文件的URL进行解释。 $.post()中的URL匹配到您将在其中调用此脚本的URL,就可以了。

根据评论进行编辑:添加一个斜杠: /php/users-profs/tryEmail.php -如果没有斜杠, /php/users-profs/tryEmail.php相对URL,因此查找错误的位置。

另外,您需要删除匿名包装器函数,因为您无法返回匿名函数,而且该函数也不会执行。 您的代码应如下所示:

function tryEmail(email)
{
    console.log("function:tryEmail, param: " + email);
    $.post("/php/users-profs/tryEmail.php", // fixed the leading / here
        {
            email:email
        },
        function(data)
        {
            console.log("function:tryEmail-post, data: " + data);
            if(data == "valid")
                return true;
            else
                return false;
        });
}

代替

"../../php/users-profs/tryEmail.php"

使用项目的基本URL,然后将文件位置与其连接

<your_project_base_url> + 'php/users-profs/tryEmail.php'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM