model.fetch成功回调不火的Firefox,但适用于Chrome [英] model.fetch success callback does not fire on firefox, but works on chrome

查看:104
本文介绍了model.fetch成功回调不火的Firefox,但适用于Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型成功回调取,一切工作正常在Chrome,但火狐不会触发事件。该请求被虽然完成后,根据控制台。

code样品:<​​/ P>

父类功能:

  DownloadUserPromotions:(回调) -  GT;
    自= @
    @model =新app.models.client({ID:。JSON.parse($饼干('jsondata'))ID})    LM = - &GT;
      的console.log4
      window.USER = self.model
      如果typeof运算回调=='功能',那么callback.call()    @ model.fetch
      成功:LM
      数据:
        关系:client_promotions
    的console.log3

查看功能:

 渲染: - &GT;
    自= @
    self.ReadUserInfo()
    的console.log1
    renderTemplate = - &GT;
      的console.log5
      #Below问题是奇怪.......#TODO
      @USER = JSON.parse(JSON.stringify(@USER))
      $(self.el)的.html clientsPromotionsTemplate
        茂德:USER.client_promotions
      $('#微调负载')。隐藏()
      self.FadeIn()    $('#微调负载')。节目()
    的console.log2
    @DownloadUserPromotions renderTemplate
    @

侧面说明:的标记TODO是一个不同的问题。奖金感谢你要跟帮助我弄清楚为什么JSON仅在错综复杂的方式。


解决方案

由于我的成功回调是一个JSON对象的一部分,Firefox无法找到任何默认情况下它一直在寻找,因此不火什么。指定数据类型:在撷取解决了此问题时,因为火狐知道去哪里寻找成功回拨JSON

浏览器显然是读我的心......

I have a success callback for a model fetch, and everything works fine on chrome, but on firefox the event does not fire. The request gets completed though, according to the console.

Code Sample:

Parent Class Function:

DownloadUserPromotions: (callback) ->
    self = @
    @model = new app.models.client({ id: JSON.parse($.cookie('jsondata')).id })

    lm = ->
      console.log "4"
      window.USER = self.model
      if typeof callback == 'function' then callback.call()   

    @model.fetch
      success: lm
      data: 
        relationships: 'client_promotions'
    console.log "3"

View Function:

render: ->      
    self = @
    self.ReadUserInfo()
    console.log "1"
    renderTemplate = ->
      console.log "5"
      #Below Issue is wierd.......#TODO
      @USER = JSON.parse(JSON.stringify(@USER))
      $(self.el).html clientsPromotionsTemplate
        promos: USER.client_promotions
      $('.spinner#load').hide()
      self.FadeIn()

    $('.spinner#load').show()
    console.log "2"
    @DownloadUserPromotions renderTemplate  
    @

Side Note: The marked TODO is a different issue. Bonus thank yous for helping me figure out why JSON works only in that convoluted manner.

解决方案

Since my success callback was part of a JSON object, firefox couldn't find whatever default it was looking for and therefore didn't fire anything. Specifying dataType:'json' when fetching solves this problem, because firefox knows where to look for the success call back.

Chrome is apparently reads my mind...

这篇关于model.fetch成功回调不火的Firefox,但适用于Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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