首页 \ 问答 \ 如果我刷新页面,POST不会完成(POST doesn't complete if I refresh page)

如果我刷新页面,POST不会完成(POST doesn't complete if I refresh page)

我有一个表单,在提交时使用$ .ajax来调用将数据写入文本文件的bash脚本。

在Firefox中,如果我立即刷新页面或导航到其他页面,POST将中止,文本文件不会更新:

[15:07:12.781] POST http://server/writegit.cgi [undefined 891ms]

如果我在刷新之前等待一两秒钟,POST就完成了,一切都很好:

[15:03:04.995] POST http://server/writegit.cgi [HTTP / 1.1 200 OK 2022ms]

但是,Chrome中不会出现此问题 - 一旦表单提交,即使我立即刷新页面,POST也会完成。

有什么方法可以让Firefox像Chrome一样?


I have a form which uses $.ajax on submit to call a bash script that writes data to a text file.

In Firefox, if i immediately refresh the page or navigate to a different page, the POST aborts, and the text file does not update:

[15:07:12.781] POST http://server/writegit.cgi [undefined 891ms]

If I wait a second or two before refreshing, the POST completes and everything is fine:

[15:03:04.995] POST http://server/writegit.cgi [HTTP/1.1 200 OK 2022ms]

However, this problem does not happen in Chrome-- once the form submits, the POST will complete even if I refresh the page immediately.

Is there any way I can make Firefox behave like Chrome?


原文:https://stackoverflow.com/questions/9608398
更新时间:2023-09-05 18:09

最满意答案

所以对于这个用例,你应该使用工厂而不是服务。

在大多数使用factory方法的情况下,它实际上应该使用service方法,并成为ES6中的一个class 。 这种情况是例外。 您需要注册一个调用$resouce factory的工厂方法。

在ES6中(如果用require替换import,大多数是ES5),它应该看起来像这样:

import {app} from '../app';    

feedLoadFactory.$inject = ['$resource'];
feedLoadFactory($resource) {

    return 
        $resource('http://ajax.googleapis.com/ajax/services/feed/load', 
            {}, {
               fetch: { 
                   method: 'JSONP', 
                   params: {v: '1.0', callback: 'JSON_CALLBACK'} 
               }
        });
}

app.factory('feedLoad', feelLoadFactory);

然后你可以注入它作为feedLoad并使用它作为feedLoad.fetch...


So for this use case you should be using a factory rather than a service.

In most cases where the factory method is used, it actually should use the service method and be a class in ES6. This case is the exception. You need to register a factory method that calls the $resouce factory.

In ES6 and (and mostly ES5 if you replace import with require) it should look something like this:

import {app} from '../app';    

feedLoadFactory.$inject = ['$resource'];
feedLoadFactory($resource) {

    return 
        $resource('http://ajax.googleapis.com/ajax/services/feed/load', 
            {}, {
               fetch: { 
                   method: 'JSONP', 
                   params: {v: '1.0', callback: 'JSON_CALLBACK'} 
               }
        });
}

app.factory('feedLoad', feelLoadFactory);

Then you can inject it as feedLoad and use it as feedLoad.fetch...

相关问答

更多
  • 所以对于这个用例,你应该使用工厂而不是服务。 在大多数使用factory方法的情况下,它实际上应该使用service方法,并成为ES6中的一个class 。 这种情况是例外。 您需要注册一个调用$resouce factory的工厂方法。 在ES6中(如果用require替换import,大多数是ES5),它应该看起来像这样: import {app} from '../app'; feedLoadFactory.$inject = ['$resource']; feedLoadFactory($ ...
  • 在tsconfig.json将module值从当前的任何值更改为es6 。 当TypeScript转换TS文件时,它将在ES6中完成。 如果您需要删除TypeScript支持并依赖纯JavaScript,则可以使用已转换的代码进行进一步的工作。 更新 如果要生成ES6代码,则需要设置target ,而不是module 。 module处理加载器。 您可以重用和更新的已转换代码的示例如下所示: var __decorate = (this && this.__decorate) || function (de ...
  • 本教程似乎使用相同的API。 这是一个似乎有用的参考实现 。 看看这个文件 。 注意作者在第1行中如何将库作为jtt_openweathermap导入到他的角度模块中? 特定的代码行看起来像这样: angular.module('myApp', ['ui.router', 'ngGeolocation', 'ngProgress', 'ui.router.title', 'jtt_openweathermap', 'ngMap']) 你也需要这样做。 我想你可能不是那样做的。 我还会在这里看一下这个控制器 ...
  • 角度constant服务只是一种在配置阶段可用的服务,是存储模块常量的建议方式(因此名称)。 它不是一个真正的常量,可以随时用$provide.constant覆盖。 链式angular.module(...)导出Module对象 ,在非Angular上下文中没有意义。 为Angular模块和ES6模块保留单独的导出。 导出Angular模块name属性是一种常规方法,该属性可以在语义上导入并在其他模块中使用。 export const foo = ...; export default angular. ...
  • 看起来你试图在保存范围之前调用使用“$ scope”的函数。 尝试移动this.scope = $ scope; 高于this.getEnterpriseData():在你的代码中: class EnterpriseController { /*@ngInject*/ constructor(enterpriseService, $scope) { this.name = 'enterprise'; this.systemId = 20003 this.pageLink = ...
  • 你以错误的方式调用put函数。 尝试使用此参数顺序: this.$cookieStore.put('authenticatedAccount', JSON.stringify(account)); You call the put function the wrong way. Try with this parameter order: this.$cookieStore.put('authenticatedAccount', JSON.stringify(account));
  • 您的代码中存在语法错误... - 不允许在类体中使用const声明(在当前语法中,您只能在其中定义方法)。 相反,您需要将此const声明为对象属性,或将其从类声明中移出。 You have syntax error in your code… - it is not allowed to have const declaration in class body(in current syntax you can define only methods there). Instead, you need t ...
  • 对于不需要使用DI service类,不应使用。 相反,服务可以定义为value并包含构造函数: class ApartmentsGridPaginator { constructor(pageSize, navRange, data) {} } app.value('ApartmentsGridPaginator', ApartmentsGridPaginator); ... class ApartmentsController { constructor(ApartmentsGridPag ...
  • eventSrv服务应该是service : angular.module(moduleName, []) .service('eventSrv', EventService); factory服务应该与工厂函数一起使用,工厂函数由注入器直接调用,ES6类应该是new编辑的。 eventSrv service should be service: angular.module(moduleName, []) .service('eventSrv', EventService); fact ...
  • 我解决了自己的问题 将PageController更改为: class PageController { constructor($scope, $state, GlobalLoading){ this.$scope = $scope; this.$state = $state; //GlobalLoading is the service I injected this.globalLoading = Glob ...

相关文章

更多

最新问答

更多
  • 您如何使用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)