Frage

I have reorganized my directory structure and my php file is not being used/called. It's as if I can't access it. My functions and the php file were working as expected before this and my file permissions are sorted out so can someone lead me in the right direction?

The directory is as follows:

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

The code:

 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;
            });
        }
    }
War es hilfreich?

Lösung

The URL ../../php/users-profs/tryEmail.php will be interpreted relative to the user's current URL, not the URL of the .js file. Match the URL in $.post() to the URL where you will invoke this script, and it will be fine.

Edit based on comment: Add a slash: /php/users-profs/tryEmail.php -- without it, it's a relative URL, so it's looking in the wrong place.

Also, you need to remove the anonymous wrapper function, because you can't return an anonymous function, and it won't execute anyway. Your code should look like this:

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;
        });
}

Andere Tipps

instead of

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

use your project's base url and then concatenate your file location to it like

<your_project_base_url> + 'php/users-profs/tryEmail.php'
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top