首页 \ 问答 \ 背景选项卡上的页面未正确加载(Page on background tab not loading properly)

背景选项卡上的页面未正确加载(Page on background tab not loading properly)

我正在使用带有jQuery的Polymer 1.0,并创建了一个小的单页应用程序。 但是,当我“在新选项卡中打开链接”时,页面不会加载。 更具体地说,它以模板形式加载并触发ajax请求以获取数据,但不会将任何数据填充到模板中。 例如,简化版本:

$(document).ready(function(){
    url = '/ajax/get_data';
    $.post(url, '', function(data) {
      if (data.data.id !== undefined & data.data.id > 0) {
        $('.gt-info-location').text(data.data.name);
        $('.gt-city-population').text(data.population);
        $('.gt-city-timezone').text(data.data.timezone);
        $('.gt-city-county').text(data.data.county);
        $('google-map')[0].latitude = data.data.latitude;
        $('google-map')[0].longitude = data.data.longitude;
        $('#location-frontpage').css('background',"url('pictures/"+data.data.image_file+"') center / cover");
        $('#location-back').css('background',"url('pictures/"+data.data.image_file+"') center / cover");
      }
    });
});

我知道$.post正在发生并从Web请求日志返回正确的数据,但是.text().css()函数都没有对页面进行任何更改。 并且,是的,在打开的选项卡中加载相同的页面工作正常。


I am using Polymer 1.0 with jQuery and have created a small single page app. When I "Open link in new tab", however, the page doesn't load. More specifically, it loads in template form and fires the ajax requests to get the data, but none of that data gets populated into the template. For example, a simplified version:

$(document).ready(function(){
    url = '/ajax/get_data';
    $.post(url, '', function(data) {
      if (data.data.id !== undefined & data.data.id > 0) {
        $('.gt-info-location').text(data.data.name);
        $('.gt-city-population').text(data.population);
        $('.gt-city-timezone').text(data.data.timezone);
        $('.gt-city-county').text(data.data.county);
        $('google-map')[0].latitude = data.data.latitude;
        $('google-map')[0].longitude = data.data.longitude;
        $('#location-frontpage').css('background',"url('pictures/"+data.data.image_file+"') center / cover");
        $('#location-back').css('background',"url('pictures/"+data.data.image_file+"') center / cover");
      }
    });
});

I know the $.post is happening and returning the correct data from the web request log, but none of the .text() or .css() functions are making any changes to the page. And, yes, loading the same page in an open tab works fine.


原文:https://stackoverflow.com/questions/36289923
更新时间:2023-12-18 11:12

最满意答案

这是一行:

return DataCenterEnum.values()[new Random().nextInt(3) + 1)];

对于那些需要更严格控制代码的人来说,这是一个更安全的版本,它不依赖于枚举实例的顺序:

return new DataCenterEnum[]{DC1, DC2, DC3}[new Random().nextInt(3)];

Here's the one line:

return DataCenterEnum.values()[new Random().nextInt(3) + 1)];

For those who require tighter control on their code, here's a safer version, which does not depend on the order of the enum instances:

return new DataCenterEnum[]{DC1, DC2, DC3}[new Random().nextInt(3)];

相关问答

更多
  • 从(例如)小写字符生成字符串: import random, string def randomword(length): letters = string.ascii_lowercase return ''.join(random.choice(letters) for i in range(length)) 结果: >>> randomword(10) 'vxnxikmhdc' >>> randomword(10) 'ytqhdohksy' Generating strings fro ...
  • phelgo , NSBarcelona的一名成员告诉我这件事,并且完美无缺! enum Localizations { static let StringId1 = NSLocalizedString("string_to_translate_1", comment: "") } let myString = Localizations.StringId1 有一个没有案例的enum可能看起来不熟悉,但是我们可以保持其所有的安全性(和代码完成),同时仍然防止Localizations被错误地实例 ...
  • 我们真的不需要手动波动你的函数有多少次迭代(或递归)。 我相信在每次调用时,预期的迭代次数是按地理分布的(即首次成功之前的试验次数由地理分布控制 ),其平均值为1 / p,其中p是成功找到未使用的字符串的概率。 我相信p只是1 - n / 63 ^ 6,其中n是当前存储的字符串的数量。 因此,我认为你需要在数据库中存储300亿个字符串(~63 ^ 6/2),然后你的函数平均每次调用的次数超过2次(p = .5)。 此外,几何分布的方差为1-p / p ^ 2,因此即使在300亿个条目中,一个标准偏差也只是s ...
  • 尝试将地图转换为像这样的列表(在Room类中): public Direction getRandomExit(){ List directions = new ArrayList(exits.keySet()); if (directions.size()==0){ return null; } Random rand = new Random(); ...
  • 这对于使用enum没有任何意义。 请记住, enum常量是单例:所有角色将共享每个技能对象的相同单个副本,因此所有角色将具有相同的技能编号。 这可能不是你想要的。 只用字段来代替字段会更有意义: public class Skills { private int vehicleSkill; private int hackingSkill; // etc. public Skills(Random r) { this.vehicleSkill = r.nex ...
  • 这是一行: return DataCenterEnum.values()[new Random().nextInt(3) + 1)]; 对于那些需要更严格控制代码的人来说,这是一个更安全的版本,它不依赖于枚举实例的顺序: return new DataCenterEnum[]{DC1, DC2, DC3}[new Random().nextInt(3)]; Here's the one line: return DataCenterEnum.values()[new Random().nextInt(3 ...
  • 在OpenOffice Calc中, RAND函数返回0到1之间的值 - 因此您必须组合不同的公式才能从两个文本值中随机选择。 需要以下步骤: 将rand的结果舍入为整数; 基于该整数,从列表中选择。 请尝试以下公式: =CHOOSE(ROUND(RAND()+1);"MBA";"MSc") 或分成不同的行: =CHOOSE( ROUND( RAND()+1 ); "MBA"; "MSc" ) 根据您的本地化,您必须替换参数分隔符; 通过: 。 说明: C ...
  • 我希望以下Snipped可以帮助你。 当然,您可以使用Stream API简化它。 但这个概念应该是清楚的。 只需将此添加到您的枚举声明中即可。 public static CursorInfo getCursor(String search) { for(CursorInfo cursorValue : CursorInfo.values()) { for(String tool : cursorValue.toolTip) { if ...
  • 你应该将你的roshambo字段存储为Roshambo而不是int并相应地更新你的setter和getter。 这是因为在Java Enums中无法将其转换为int 。 有关说明,请参阅下面的堆栈溢出链接: 在Java中将Int转换为枚举 字段名称应以小写字母开头 使用Roshambo.values()[choice] 摆脱1 + in 1 + rand.nextInt(3); 因为nextInt()方法在位置0中具有第一个枚举值。所以 Roshambo.values()[0] = ROCK Roshamb ...
  • 您的RandomEnumSequenceGenerator版本不检查request ,因此它只响应任何请求,即使它不是它定制类型的请求。 最简单的解决方案可能是这样的: public class RandomEnumSequenceGenerator : ISpecimenBuilder where T : struct { private static Random _random = new Random(); private Array _values; publ ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)