小编Abh*_*mar的帖子

Javascript从数组内的对象中获取值

我在数组中有一个键值对的对象:

var data = [
  {
  "errorCode":100,
  "message":{},
  "name":"InternetGatewayDevice.LANDevice.1.Hosts.HostNumberOfEntries",
  "value":"2"
  }
];
Run Code Online (Sandbox Code Playgroud)

我想获取对象中“value”键的值。即,输出应为“2”。

我试过这个:

console.log(data[value]);
console.log(data.value);
Run Code Online (Sandbox Code Playgroud)

两者都记录“未定义”。我在 SO 本身中看到了类似的问题。但是,我无法为我的问题找到解决方案。

javascript arrays object

9
推荐指数
4
解决办法
4万
查看次数

PHP客户端向服务器端发送请求并向远程服务器发送服务器端请求

我的方案如下:

  1. 单击按钮时,客户端将向服务器端发送请求
  2. 一旦服务器端收到请求,它将向远程服务器发送另一个请求以获得结果
  3. 一旦响应到来,服务器端应该回应客户端的响应.

客户

$.post('login_server.php'{act:"post",phone:phone,passwords:passwords},function(e){
      alert(e);
    },'json');
Run Code Online (Sandbox Code Playgroud)

服务器

$act = isset($_POST["act"]) ? $_POST["act"] : "default";
if($act == "default"){
    var_dump(123123);
}elseif($act == "post"){
    $phone = $_POST["phone"];
    $password = md5($_POST["passwords"]);
    $data_array = array('phone' => $phone,'password' =>$password );
    $jsonStr = json_encode($data_array);
    $url = "http://xx.xx.xx.xx/xxxx/userinfo/login";
    $data = http_post_json($url, $jsonStr); 
    echo json_encode(123);  
}

function http_post_json($url, $jsonStr)
{
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                      'Content-Type: application/json; charset=utf-8',
                      'Content-Length: ' . strlen($jsonStr)
                )
            ); …
Run Code Online (Sandbox Code Playgroud)

php post curl

6
推荐指数
1
解决办法
987
查看次数

标签 统计

arrays ×1

curl ×1

javascript ×1

object ×1

php ×1

post ×1