JQuery,Ajax:Serialize()不适用于< select>在IE中? [英] JQuery, Ajax: Serialize() not working with <select> in IE?

查看:303
本文介绍了JQuery,Ajax:Serialize()不适用于< select>在IE中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为表单选择过滤创建了一个小脚本。
我的目标是,当用户选择我们说的field1时,然后将field2get替换为一个带有PHP的过滤器,只剩下选择(通过数组中的数据完成)。



我的JQuery在几乎所有现代浏览器中都能正常工作:

  $(。 ()
var $ form = $('form');
var $ fields = $(。ajx);
var方法= $ form.attr(method)。toUpperCase();
var $ this = $(this);
// var $ ser = $ fields.serialize();
var $ ser = $ this.serialize();

console.log($ ser);
//console.log($(this))

$('。ajx_load')。show();

$ .ajax({
url:$ form.attr(action),
data:$ ser,
type:method,
success:function(res){
//$('.ajx').html($(res).find('.ajx div'));
//$this.html($(res).find('.ajx div'));

var $ fnd ='#' + $ this.attr('id')+'div';
$ this.html($(res).find($ fnd));

console.log($ this.attr('id'));
console.log($ this.html($(res).find($ fnd)));

$('。ajx_load')。hide();
},
error:function(xhr,status){
$('。ajx_load')。hide();
alert('未知错误 - 状态:'+状态);
}
});
});

代码应该重新载入< fieldset class =axj中的html代码id =ajx_1>< div> ,保留对该字段的选择并替换此处的所有< select> 字段< fieldset> 通过PHP过滤。



以下是HTML输出(不含PHP):< a href =http://jsfiddle.net/69rvLtcn/8/ =nofollow> http://jsfiddle.net/69rvLtcn/8/

serialize()函数在IE(测试IE11)和Safari中不起作用 - 它是空的!



在此先感谢您的帮助

编辑:
我试图在success:function中设置setTimeout()。
当我这样做的时候(甚至当我把它设置为1),IE / Safari中发生的事情也会发生在其他所有浏览器上......?



这就像在JQuery响应中不传输选择内容!!

编辑2:它毕竟是IE!它以某种方式不会序列化请求...?如果我在PHP中,我使用IE $ Safari中的 var_dump($ _ REQUEST); 检查请求,在所有其他情况下它是空的...



JQuery:



blockquote>

应该在表单或者一组输入上调用.serialize()方法。

来源: http://bugs.jquery.com/ticket/9863


I did create a little script for form select filtering. My goal is, that when the user selects something in let's say "field1", then "field2" get's replaced by a filtered one with PHP with only the selection left (done via data in an array).

My JQuery works fine in almost every modern browser:

$(".ajx").on("change", function() {
    var $form = $('form');
    var $fields = $(".ajx");
    var method = $form.attr("method").toUpperCase();
    var $this = $(this);
    //var $ser = $fields.serialize();
    var $ser = $this.serialize();

    console.log($ser);
    //console.log($(this))

    $('.ajx_load').show();

    $.ajax({
        url: $form.attr("action"),
        data: $ser,
        type: method,
        success: function(res) {
            //$('.ajx').html($(res).find('.ajx div'));
            //$this.html($(res).find('.ajx div'));

            var $fnd = '#' + $this.attr('id') + ' div';
            $this.html($(res).find($fnd));

            console.log($this.attr('id'));
            console.log($this.html($(res).find($fnd)));

            $('.ajx_load').hide();
        },
        error: function (xhr, status) {  
            $('.ajx_load').hide();
            alert('Unknown error - status: ' + status); 
        }
    });
});

The code should reload the html code in <fieldset class="axj" id="ajx_1"><div>, keep the selection made on the field and replace all <select> fields in this <fieldset> by filtered ones via PHP.

Here is the HTML output (without PHP) used: http://jsfiddle.net/69rvLtcn/8/

The serialize() function does not work in IE (tested in IE11) and Safari - it is empty!

Thanks in Advance for your help

EDIT: I tried to set a setTimeout() in the "success: function". When I do this (even when I set it to 1) the same thing that happens in IE/Safari then happens on every other Browser too...?

It's like the selection is not transmitted in the JQuery response?!

EDIT2: It's IE after all! It somehow doesn't serialize request...? If I in PHP I check the request with var_dump($_REQUEST); in IE/Safari it's empty in all others not...

解决方案

Got the solution:

JQuery:

The .serialize() method should be called on a form or on a set of inputs.

Source: http://bugs.jquery.com/ticket/9863

这篇关于JQuery,Ajax:Serialize()不适用于&lt; select&gt;在IE中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆