jQuery.load()在Firefox下响应错误,在Chrome下运行正常

Aka*_*sha 3 javascript ajax firefox jquery google-chrome

我有一个功能,在对话框而不是主窗口中打开一个页面.有点清理的代码如下:

var baseurl = window.location.origin + '/static/docs/'

function onClickLink(event) {
  event.preventDefault();
  if ($("#dialog").length == 0) {
    setUpDialog()
  }
  var href = event.target.href;
  href = baseurl + href.substring(1 + href.lastIndexOf('/'));
  $("#dialog").load(href + ' .body', function(response, status, xhr) {
    if (status == "error") {
      window.location = event.target.href;
    } else {
      changeImageSrc();
      reStructure();
    }
  });
  $("#dialog").dialog({
    modal: true,
    title: event.target.text,
    width: 960,
    position: ['center', 100]
  });
}
Run Code Online (Sandbox Code Playgroud)

此代码在Chrome中运行良好,但(状态=="错误")在Firefox下执行.看起来Firefox有404错误,可能是加载页面的图像,或者类似的东西.

有关如何在Firefox下获得Chrome行为的任何想法吗?(你可以在这里找到一个有效的例子)

Sal*_*n A 10

  1. 在FireFox中,window.location.origin是undefined.FireFox因此厌倦了获取页面:

    http://openerp.co.hu/hu/funkcionalis-bemutato/undefined/static/docs/sales.html

    并失败

  2. 在chrome中,window.location.origin http://openerp.co.hu.Chrome绑定以获取该页面:

    http://openerp.co.hu/static/docs/sales.html

    并成功

而不是依赖window.location.origin,尝试使用:

window.location.protocol + "//" + window.location.host
Run Code Online (Sandbox Code Playgroud)