jquery ajax切断IE中的响应 [英] jquery ajax cutting off response in IE

查看:69
本文介绍了jquery ajax切断IE中的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jquery表单插件,该插件使用jquery ajax来完成其大部分工作.我们有jQuery 1.7.2

I am using the jquery form plugin which uses jquery ajax to do most of its work. We have jquery 1.7.2

我们正在使用它通过ajax将表单发送到服务器,并返回表示成功的值或返回带有验证错误的表单.

We are using it to send a form via ajax to the server and either return a value indiciating success or return the form with validation errors.

当在验证中发现错误时,我让它在firefox和chrome中工作.包含旧格式的div的内容将替换为有错误的新格式.

I have it working in firefox and chrome when an error is found in validation the contents of a div containing the old form are replaced with the new one that has the errors.

$('#FormDiv').empty().html(response);

$('#FormDiv').empty().html(response);

响应如下所示:

<form action="/MyForm/Edit" id="MyForm" method="post"><input id="Id" name="Id" type="hidden" value="" />
    <input id="PlantId" name="PlantId" type="hidden" value="1" />
    <table>
        <tr><td class="field">
                ID
            </td>
            <td>
                <input class="required" id="MyId" name="MyName" type="text" value="JP001" />

            </td>
            <td class="field">Description</td>   
            <td><input class="required" id="Description" name="Description" type="text" value="" />
        </tr>
        <tr>
            <td class="field">Created by</td>
            <td>Joe Bloggs</td>
            <td class="field">Create date</td>
            <td>15/06/2012</td>
        </tr>
    </table>
</form>

在IE中进行调试,我可以看到ajax调用实际上在其返回正文中具有此功能,但是我方法的参数是删除外部形式的开始和结束标记,因此本质上它只是一个表.

Debugging in IE the I can see that the ajax call actually has this in its return body however the parameter to my method is removing the outer form starting and ending tags so essentially it is just a table.

我尝试了几种不同的方法来尝试解决此问题,包括将processData设置为false(不确定是否确实会影响它)以及将returnType设置为"text"和"html",但没有任何帮助.

I have tried a few different things to try and figure this out including setting processData to false (not sure if that would really affect it anyway) and setting the returnType to "text" and "html" but none really helped.

有什么想法吗?

因此,事实证明,如果我将表格包装在div中,一切似乎都可以正常工作,不太确定那里发生了什么,如果有人可以解释这一点,他们就可以得到答案

So it turns out that if i wrap the form in a div everything seems to work ok, not quite sure whats going on there, if anyone can explain this they can have the answer

推荐答案

这不是jQuery错误.

It's not a jQuery bug.

这是一个不太知名的Javascript功能"

It's a not-so-well-known Javascript "feature"

显然,FF3和IE6 +(也许还有其他)中的innerHTML不喜欢将表单标签用作 innerHTML 的一部分.如果需要,可以对其进行测试:

Apparently innerHTML in FF3 and IE6+ (And maybe others) don't like form tags as part of innerHTML. If you want, you can test it:

<div id="test">
   <form>
      <input>
   </form>
</div>

<script>
    window.onload=document.getElementById('test').innerHTML = "<form><input type="hidden" name="blah"></form>";
</script>



Result:

<div id="test">
    <input type="hidden" name="blah">
</div>

不太清楚为什么,但这就是 他们 的实现方式.

Not quite sure why, but that is how they implement it.

这篇关于jquery ajax切断IE中的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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