I have the following HTML:

我有以下HTML:

<input type="checkbox" id="options_1" value="options_1" name="options[]">  
<input type="checkbox" id="options_2" value="options_2" name="options[]">  
<input type="checkbox" id="options_3" value="options_3" name="options[]">  

I check the first two options and send it to the server via ajax in jQuery:

我检查了前两个选项,并通过jQuery ajax发送到服务器:

$.ajax({
    type: "POST",
    url: "myfile.php",
    data: {
        'options':$('input[name="options[]"]').serialize()
    },
    dataType: 'json',
    beforeSend: function(){
           //do some stuff
    },
    success: function(msg){
        //do some stuff
    }
});

Firebug shows me the data that has been posted:

Firebug向我显示已发布的数据:

options options%5B%5D=options_1&options%5B%5D=options_2
So far, so good.

In myfile.php I get the POST-Variable like this:

选项选项%5B%5D=options_1&选项%5B%5D=options_2,到目前为止,很好。在myfile。php后变量如下:

$options = $_POST['options'];

Now when I echo $options I get this:

当我回复$options时,我得到了这个:

"options[]=options_1&options;[]=options_2"

Where does this semicolon in front of the second pair of brackets come from? This is driving me crazy.

在第二对括号前面的分号来自哪里?这让我发疯。

I already used utf8_decode on the POST data as well as urldecode and rawurldecode. Nothing changes. I also escaped the square brackets in the ajax call like this:

我已经在POST数据上使用了utf8_decode以及urldecode和rawurldecode。没有什么变化。我还将ajax调用中的方括号转义为:

data: {
    'options':$('input[name="options\\[\\]"]').serialize()
},

That didn't help either. Any ideas anyone?

这没有任何帮助。有什么想法吗?

4 个解决方案

#1


2

I had this exact problem, and I was only able to get it to work by using ".serializeArray()", I hope this was what you were looking for.

我遇到了这个问题,我只能通过使用“.serializeArray()”来使它工作我希望这就是你想要的。

data: {
    'options':$('input[name="options[]"]').serializeArray()
},

For me this outputs standard string in the same format as GET requests.

对于我来说,它以与GET请求相同的格式输出标准字符串。

更多相关文章

  1. php怎么读取MYSQL数据到radio选项
  2. 如何在HTML选择选项列表中保留空间hi
  3. 如何让react-native Picker保持新选择的选项?
  4. 如何为select中的选项创建?
  5. AngularJS(1.5.8) - 如何直接从获取json对象的控制器中填充选择选
  6. FieldErro:无法将关键字'date_added'解析为字段。选项包括:data_ad
  7. ubuntu 16.04 设置选项里面找不到《打印机》和《软件和更新》两
  8. Linux 3.4.39内核编译配置选项介绍
  9. ubi文件系统制作,还是"-c"选项的问题

随机推荐

  1. android:shape的使用2
  2. recycleView的item获取焦点
  3. Android--使用include调用布局
  4. android高版本系统源码下载和编译刷机
  5. 自定义图片点击效果
  6. Android:搭建NDK环境(Cygwin+android-NDK)
  7. Android矢量动画-VectorDrawable
  8. Android studio3.6的JNI教程之helloworld
  9. android 使用TextView/EditText应该注意
  10. TextView字间距和行间距设置