[英]passing a php array through jquery ajax
I want to pass an array through ajax, but not sure how I would do this. 我想通过ajax传递一个数组,但不知道我会怎么做。
<input type="button" data-array="'.$array.'" id="button" value="click">
I know I cant put arrays in html, but I couldnt think of how else to explain what I am trying to accomplish. 我知道我不能把数组放在html中,但我无法想到如何解释我想要实现的目标。
$('#button').click(function(){
array = $(this).attr('data-array');
$.ajax({
type : 'POST',
dataType : 'json',
url : 'ajax.php',
data : 'array='+array,
success : function(data) {
$('#result').html(data);
}
});
});
So I then want to pass that array variable, $array, through to ajax.php. 所以我想把那个数组变量$ array传递给ajax.php。 Is this even possible, if so how is it done?
这是否可能,如果是这样,它是如何完成的? I am guess something to do with json?
我猜想和json有什么关系?
您可以将它存储在会话变量中,并在需要时稍后调用它,而不是将数组存储在html中。
$_SESSION['dataArray'] = $array;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.