简体   繁体   English

将数据从 javascript 发送到 php 不起作用:结果 null

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

So my javascript file looks like this:所以我的 javascript 文件看起来像这样:

$(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: php 的位如下:

echo $_POST["url"];

Now, as you can see what I'm trying to do is sending the current url of the site to php.现在,正如您所看到的,我正在尝试将站点的当前 url 发送到 php。 But the only output I get from console.log(data);但是我从 console.log(data) 得到的唯一 output; is null.是 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"];
 })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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