weixin_33709219 2010-09-25 11:23 采纳率: 0%
浏览 50

IE8中的jQuery ajax()调用失败

I have the following code for submitting data using ajax from forms of class ajax. this works perfectly in Firefox, Safari and Chrome but fails in IE.

ajax: function() {
      $('form.ajax').live('submit', function() {
        var form_ajax = $(this);

        $.ajax({
          url: form_ajax.attr('action'),
          data: form_ajax.serialize(),
          type: form_ajax.attr('method'),
          dataType: 'script',
          beforeSend: function(xhr) {

            $('#ajax-bid-new .ajax-form-error, #ajax-bid-new .ajax-form-success').remove();
            form_ajax.slideUp();

          }
        });

        return false;
      });

Please help - I am stuck here for past 2 days. I am returning a Javascript file from server to be evaluated inside browser. This works as expected in Firefox, Chrome and Safari, but IE receives it as a file and opens up the file download dialog.

What can I do in IE to make this work? I tried by dropping the following code in my application.js file (I'm doing a rails project btw)

// public/javascripts/application.js
jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})

I get the same behavior from IE even after writing the ajaxSetup block like above.

  • 写回答

3条回答 默认 最新

  • python小菜 2010-09-25 11:27
    关注

    Looks like live doesn't work with submit in IE. Have you tried using a normal submit instead:

    $('form.ajax').submit(function() {
    
    评论

报告相同问题?

悬赏问题

  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)