从OpenLayers JavaScript接收PHP的POST请求

Geo*_*ssi 2 javascript php post openlayers

我在PHP中接收POST请求时遇到问题.我正在使用JavaScript将数据发送到带有POST请求的PHP页面.JavaScript来自OpenLayers.js,发送请求的部分如下所示:

var postrequest = OpenLayers.Request.POST({
        url: "http://localhost/index.php",
        data: "success",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        }
    });
Run Code Online (Sandbox Code Playgroud)

在PHP中,我正在使用此代码来查看,我得到了什么:

<?php
    print_r($_POST);
?>
Run Code Online (Sandbox Code Playgroud)

这是发生的事情:

  1. index.php接收POST请求.
  2. FireBug还会通知POST参数包含已发送的成功.
  3. 的print_r($ _ POST); 在index.php中只提供了这个:array()并且在来自JavaScript的POST请求后没有改变.

所以发送和接收数据,但我的PHP代码不知道它,或者我没有使用正确的PHP函数.

任何建议,在哪里寻找,以及尝试什么?

Jam*_*mes 5

我认为"data"属性需要是包含键/值对的对象.

例如:

var postrequest = OpenLayers.Request.POST({
        url: "http://localhost/index.php",
        data: {
          userName: "myUsername",
          password: "myPassword"
        },
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        }
    });
Run Code Online (Sandbox Code Playgroud)

如果你在print_r($ _ POST)时有效,你应该看到数组("userName"=>"myUsername","password"=>"myPassword")