jquery and IE submit, ajaxForm not working

自古美人都是妖i 提交于 2020-01-04 03:12:15

问题


I have a form:

<form method="post" action="/balda/server.wsgi" id="gameboard" name="gameboard" >

with a submit button:

<input type="submit" name="submit" value="Поиск" style="" onmouseover="CheckElements();">

the submit button should send ajax bind process:

jQuery(document).ready(function(){
    jQuery('#gameboard').submit( function() {
        $.ajax({
            url     : $(this).attr('action'),
            type    : $(this).attr('method'),
            dataType: 'json',
            data    : $(this).serialize(),
            success : function( data ) {
                       onAjaxSuccess( data );
                    }
        });
        return false;
    });
});

There are accepted function:

function onAjaxSuccess (result)

All this works fine in chrome, ff, opera, safari, but it does not work in Internet Explorer 9 (others not tried it)

In IE9, the result variable is empty. I tried another bind submit button like this:

$('document').ready(function( result )
{
    $('#gameboard').ajaxForm( {    
        type: "POST",
        data    : $(this).serialize(),
        success: onAjaxSuccess,
        dataType: 'json',
        error: function(){ alert ( 'Error loading data format.' ); }
    }); 
});

But the result is the same ff chrome safari opera work, except for IE9 .

Please tell me what could be the problem.


回答1:


The problem was that IE9 does not understand the format of "JSON" in the encoding cp1251, even though it is clearly stated in the response header. Translation of the JSON response in utf-8 solved the problem with IE9.




回答2:


make sure there is no space in the type="text/javascript" if there is space in defining type of script then IE wont allows your js to work

<script type="text/javascript">
  ....... 
</script>


来源:https://stackoverflow.com/questions/10563748/jquery-and-ie-submit-ajaxform-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!