即与ajax html响应问题 [英] ie problem with getting ajax html response

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

问题描述

我有一个提交一些数据并返回html的表单.该html用来替换页面上的现有div.

i have a form that submits some data and gets html back. this html is used to replace an existing div on the page.

在FF和chrome中,它接收html并呈现良好效果.问题是在IE中,它完全忽略"我的成功函数,并在新页面上呈现接收到的html,这不是预期的功能.我该如何告诉我不要这样做,而只是遵循成功功能?

in FF and chrome, it receives the html and renders fine. Problem with this is that in IE, it "ignores" my success function altogether and renders the received html on a new page, which is not the intended function. how do i tell ie not to do this and just follow the success function?

我忘了提到这种情况仅在按"Enter"键(有效提交表单)时发生.使用firefox和chrome,它仍然通过ajax提交表单,但是,也就是说,它通过HTML提交表单,这将我转发到该html部分响应

I forgot to mention that this only happens when pressing "Enter" (effectively submitting the form). With firefox and chrome, it still submits the form via ajax, but in ie it submits the form via HTML, which forwards me to that html partial response

$(".toggle-form-submit").parents("form").live("submit", function(){
  console.log("WHO");
  $.ajax({
    dataType: 'js',
    type: 'POST',
    url: myForm.attr("action"),
    data: myForm.serialize(),
    success: function(html) {
      alert("WTF");
      if(myForm.parents("fieldset").find(".replaceable").length) {
        updateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
      } else {
        longPanelUpdateReplaceableAndClearAndCloseFormWithin(myForm.parents("fieldset"), html);
      }
      if( $(".test-categories-list").length) {
        initSortableTestCases();
      }
    }
  });
});

推荐答案

您正在告诉它单击提交"按钮时运行JS……不是.

You are telling it to run the JS when the submit button is being clicked … which it isn't.

$(".toggle-form-submit").live('click',

应该是:

$("form").live('submit',

…,但是请确保当JS不运行时,结果仍然有意义.您不能保证用户(或他们的sysad,连接不良或其他原因)不会阻止JS.

… but make sure that when the JS doesn't run, the result stills makes sense. You can't guarantee that the user (or their sysad, or a bad connection, or something else) won't block the JS.

这篇关于即与ajax html响应问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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