是否有通过查询字符串传递数组的标准方法?
为了清楚起见,我有一个包含多个值的查询字符串,其中一个值是数组值.我希望将查询字符串值视为数组 - 我不希望数组被展开,以便它与其他查询字符串变量无法区分.
此外,根据这篇帖子的答案,作者建议不定义对数组的查询字符串支持.这准确吗?
编辑:
基于@Alex的回答,没有标准的方法可以做到这一点,所以我的后续工作是什么是一种简单的方法来识别我正在阅读的参数是PHP和Javascript中的数组?
将多个参数命名为同名是否可以接受,这样我知道它们属于一个数组?例:
?myarray=value1&myarray=value2&myarray=value3...
Run Code Online (Sandbox Code Playgroud)
或者这是不好的做法?
我正在使用FormData上传文件.我还想发送一系列其他数据.
当我发送图像时,它工作正常.当我将一些文本附加到formdata时,它工作正常.当我尝试在下面附加'tags'数组时,其他一切工作正常但没有发送数组.
FormData和附加数组的任何已知问题?
实例化formData:
formdata = new FormData();
我创建的数组.Console.log显示一切正常.
// Get the tags
tags = new Array();
$('.tag-form').each(function(i){
article = $(this).find('input[name="article"]').val();
gender = $(this).find('input[name="gender"]').val();
brand = $(this).find('input[name="brand"]').val();
this_tag = new Array();
this_tag.article = article;
this_tag.gender = gender;
this_tag.brand = brand;
tags.push(this_tag);
console.log('This is tags array: ');
console.log(tags);
});
formdata.append('tags', tags);
console.log('This is formdata: ');
console.log(formdata);
Run Code Online (Sandbox Code Playgroud)
我是怎么发的:
// Send to server
$.ajax({
url: "../../build/ajaxes/upload-photo.php",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function (response) {
console.log(response);
$.fancybox.close();
}
});
Run Code Online (Sandbox Code Playgroud)