I want to pass an array through ajax, but not sure how I would do this.
<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.
$('#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. Is this even possible, if so how is it done? I am guess something to do with json?
您可以将它存储在会话变量中,并在需要时稍后调用它,而不是将数组存储在html中。
$_SESSION['dataArray'] = $array;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.