繁体   English   中英

设置dataType脚本时IE不会触发jQuery Ajax成功

[英]IE not triggering jQuery Ajax success when set dataType script

$.ajax({
      url: '/comment_rewards/' + comment_reward_id + '/pay.js',
      type: 'POST',
      data: {channel: reward_style, reward_num: reward_num},
      dataType: "script",
      cache: true
    })
    .done(function() {
      console.log("success");
      reward.closeShade()
      reward.infoPrompt("支付成功!", "success")
    })
    .fail(function() {
      console.log("error");
    })
    .always(function() {
      console.log("complete");
    });

将dataType设置为任何其他可用的响应类型都可以使用,并且控制台“成功”,但是响应js文件不起作用。 在Firefox,Webkit(Safari,Chrome)中运行。 在IE控制台中出现“错误”的任何想法?

默认情况下,IE可能未设置X-Requested-With:XMLHttpRequest标头。 通过使用常规headers属性将其添加到Ajax调用中来手动设置它。

$.ajax({
  url: '/comment_rewards/' + comment_reward_id + '/pay.js',
  type: 'POST',
  data: {channel: reward_style, reward_num: reward_num},
  headers:{
      X-Requested-With: "XMLHttpRequest"
  }
  dataType: "script",
  cache: true
})

检查$ ajax的在线文档以检查如何设置标题。 https://api.jquery.com/jquery.post/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM