Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading