[" cus_AKIT4Rz6NHlKMa"" cus_AKIP3muBIL95H0"" cus_AKI1l8vRoFhUyK"" cus_AKI0B1DHs2IBxB"" cus_AKHxuw8UvlwH8v& #34;" cus_AKHx6iyvJJOwWe"" cus_AK03kmAOGCziJ8"]
上面的数据是下面代码的结果,它来自我在Kuha.php上创建的PHP数组
function StartRetrieve()
{
var a = $('#selType').val();
$.ajax({
type:"POST",
url:"Kuha.php",
data:'&Type='+a,
datatype:'json',
cache:false,
success:function(s){
alert(s);
}
})
}
如何访问每个数据并将其分开? 因为当我使用
for (var i = 0; i <= s.length; i++) {
$('#tb').append('<tr><td>'+s[i][0]+'</td></tr>');
}
[&#34; &#34;]包括在内,它像
一样垂直打印[
"
c
u
s
A
K
I
T
4
R
z
...
"
]
我想将结果分开并水平打印
cus_AKIT4Rz6NHlKMa
cus_AKIP3muBIL95H0
cus_AKI1l8vRoFhUyK
这是Kuha.php
<?php
function httpGet($url) {
$ch = curl_init();
$headers = array('Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxx');
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output=curl_exec($ch);
curl_close($ch);
$output = json_decode($output,true);//only necessary if the result of $output is a json encoded array
return $output;
}
$Type = $_POST['Type'];
$url = "https://api.stripe.com/v1/".$Type;
$array = httpGet($url);
$id = '';
foreach($array["data"] as $a){
$id .= $a['id'];
$id .= ',';
}
//echo $id;
$a = rtrim($id,',');
$a = explode(',', $a);
echo json_encode($a);
?>
感谢那些愿意回答的人。
答案 0 :(得分:2)
var s = ["cus_AKIT4Rz6NHlKMa", "cus_AKIP3muBIL95H0", "cus_AKI1l8vRoFhUyK", "cus_AKI0B1DHs2IBxB", "cus_AKHxuw8UvlwH8v", "cus_AKHx6iyvJJOwWe", "cus_AK03kmAOGCziJ8"];
var tr = $('<tr/>');//comment this for vertical
for (var i = 0; i < s.length; i++) {
//var tr = $('<tr/>');//comment this for horizontal
tr.append('<td>' + s[i] + '</td>');
$('#tb').prepend(tr);
}
td {
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tb"></table>
在成功函数中使用它只需删除var s的初始化