Home > OS >  Sending data from javascript to php isn't working: Result null
Sending data from javascript to php isn't working: Result null

Time:09-05

So my javascript file looks like this:

$(document).ready(function() {
     var map = { 
          url: window.location.pathname //get URL without domain
     };
     $.post("/php/SongOutput.php", {map}).done(function(data){
          console.log(map); //Check that the map is correct
          console.log(data); //Show the value of $_POST["url"];
     })
});

And the bit of php is the following:

echo $_POST["url"];

Now, as you can see what I'm trying to do is sending the current url of the site to php. But the only output I get from console.log(data); is null. How can I fix this?

CodePudding user response:

$.post("/php/SongOutput.php", map).done(function(data){
      console.log(map); //Check that the map is correct
      console.log(data); //Show the value of $_POST["url"];
 })
  • Related