0

I am trying to understand a $.ajax call:

var url = "/api/followuser.php/"  + userID ;

$.ajax(url, { 'success': function(data) {
                    /do something
                     }
});

Thia ajax call is required to pass the variable 'userID' to the file '/api/followuser.php' to make a database query(php/Mysql).

I don't have access to '/api/followuser.php' .

Can anyone help me figure out how to get the variable 'userID' from the URL in a php file to be used in a database query.( I know how to pass variable as 'data: userID,' in $.ajax and use it in a php file but i want to understand this particular example)

1
  • There is likely a mod_rewrite action on the server in question, which is an interpretation of a standard url, like the other answer from @tadman suggests. check for .htaccess files if you're on apache, or other configuration files at the server level. Commented Nov 25, 2014 at 19:34

2 Answers 2

1

Maybe you mean followuser.php?user_id= instead? The slash is probably causing issues since that's interpreted as a directory by the server:

var url = "/api/followuser.php?user_id=" + userID;
Sign up to request clarification or add additional context in comments.

3 Comments

Is this the only option because actually its written like url = base.api + "/" + userID ; and base.api = "/api/followuser.php";
That's highly irregular. Are you sure?
Yes. I don't know what you mean by 'highly irregular' but the "/" is definitely there instead of ?.
1

you need to use GET method with ajax, to do this you can use next example

$.ajax({
     url: "/api/followuser.php",
     type: "GET",
     data: {variable: "valueofvariable"},
     success:  function(data) {
        console.log(data);
     }
});

so in your php file you can read the variable like this

<?php

    if(isset($_GET["variable"])){
     echo $_GET["variable"];
     // if this works you should see in console 'valueofvariable'
    }

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.