表submition与jQuery没有与IE8的正常工作 [英] Form submition with jQuery is not working correctly with IE8

查看:146
本文介绍了表submition与jQuery没有与IE8的正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery的 $。阿贾克斯()似乎并没有与IE8的正常工作,但它正在与火狐,Chrome和Safari。我在 JSON 格式submittin的形式和响应返回。

jQuery $.ajax() does not seem to work correctly with IE8 but it is working with Firefox, Chrome and Safari. I am submittin the form and response back in JSON format.

这是我的code:


test.php的:

<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="jsFile.js"></script>

<form action='_test.php' method='post' class='ajaxform'>
 <input type='text' name='txt' value='Test Text'>
 <input type='submit' value='submit'>
</form>

<div id='testDiv'></div>

_test.php:

<?php
      $arr = array( 'testDiv' => $_POST['txt'] );
      echo json_encode( $arr );
?>

jsFile.js:

jQuery('.ajaxform').live('submit', function(event) {

 $.ajax({
        url  : $(this).attr('action'),
        type : $(this).attr('method'),
        dataType: 'json',
        data : $(this).serialize(),
        success : function( data ) {
     for(var id in data) {
      jQuery('#' + id).html( data[id] );
     }
            }
    });

 return false;
});

行为:


在火狐,Chrome,Safari浏览器:

当我提交表单的值文本框(TXT)成功填充 DIV(testDiv)不影响整个页面。

When I submit the form then value of textfield(txt) is successfully populated in DIV(testDiv) without disturbing whole page.

在IE浏览器:

当我提交表单,它只是显示在屏幕上像这样JSON形式: {testDiv:测试文本}

When I submit the form then it just shows json form on screen like this: {"testDiv":"Test Text"}

如何解决这个问题,在IE浏览器?

How to solve this problem in IE?

感谢。

推荐答案

我取代我jQuery的code这点,它是工作在所有浏览器:

I replaced my jquery code with this and it is working on all browsers:

jQuery(document).ready(function(){

    jQuery('.ajaxform').submit( function() {

        $.ajax({
            url     : $(this).attr('action'),
            type    : $(this).attr('method'),
            dataType: 'json',
            data    : $(this).serialize(),
            success : function( data ) {
                        for(var id in data) {
                            jQuery('#' + id).html( data[id] );
                        }
                      }
        });

        return false;
    });

});

我不知道这是什么,但它现在的工作。感谢所有参与和帮助我解决这个问题。

I don't know what is this but it is working now. Thanks to all to participate and help me to solve this issues.

这篇关于表submition与jQuery没有与IE8的正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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