即获得ajax html响应的问题

时间:2011-03-21 05:59:34

标签: jquery

我有一个提交一些数据并获取html的表单。这个html用于替换页面上的现有div。

在FF和chrome中,它接收html并呈现正常。问题在于,在IE中,它完全“忽略”我的成功函数,并在新页面上呈现接收的html,这不是预期的功能。我怎么告诉ie不要这样做,只是按照成功功能?

我忘了提到只有在按下“回车”(有效提交表格)时才会发生这种情况。使用firefox和chrome,它仍然通过ajax提交表单,但是它通过HTML提交表单,然后将HTML转发给html部分响应

$(".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();
      }
    }
  });
});

1 个答案:

答案 0 :(得分:0)

你告诉它在点击提交按钮时运行JS ......它不是。

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

应该是:

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

...但要确保当JS没有运行时,结果仍然有意义。您不能保证用户(或他们的系统或连接错误或其他东西)不会阻止JS。

相关问题