简体   繁体   中英

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

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?

$.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"];
 })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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