在javascript .send函数中传递数组

This is regarding passing an array to a php page.Is it possible to send an array like this(code below)? if its not possible , what changes should i bring about to my code?

function ajax_post(){    
var hr = new XMLHttpRequest();    
hr.open("POST", "get_numbers.php", true);  
hr.setRequestHeader("Content-type", "application/json");    
hr.onreadystatechange = function() {
    if(hr.readyState == 4 && hr.status == 200) {
        var data = JSON.parse(hr.responseText);
        var results=document.getElementById("ace");
        //results.innerHTML=data.u1.port;
        for (var obj in data)
       {
        results.innerHTML+=data[obj].port;
       }
    }
} 
var cards= new Array();
cards[0]="hearts";
cards[1]="spades";
hr.send(cards); 
results.innerHTML = "processing...";
}
查看全部
dongyan1993
dongyan1993
2013/12/11 20:38
  • json
  • php
  • arrays
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复