带刷新和不带刷新的 Angularjs 表单 [英] Angularjs form with and without refresh

查看:26
本文介绍了带刷新和不带刷新的 Angularjs 表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过以下方式使用 Angularjs 表单指令:如果它在/home 中,则重定向到/search/term 并且如果已经在/search 进程中,则提交而无需刷新页面,只需更改位置.我知道如何同时执行这两项操作,但我不知道如何编写可在两个示例中均适用的可重用代码.

I would like to use an Angularjs form directive in the following way: if it's in /home redirect to /search/term and if already in /search process the submit without page refresh just changing the location. I know how to do both, but I don't know how to write a reusable code which works in both examples.

推荐答案

除非您通过 XHR 异步提交数据,否则您将无法在没有页面刷新的情况下提交表单数据.

You won't be able to submit form data without a page refresh, unless you submit the data asynchronously via XHR.

听起来您是通过 HTTP POST 或/home 上的 GET 同步提交,这会导致页面刷新.您需要编写一些 Angular 代码来从表单控件中获取值并通过 XHR POST 或 GET 提交.

It sounds like you are submitting synchronously via HTTP POST or GET at /home, which would result in a page refresh. You will need to write some Angular code to take the values from the form controls and submit it via XHR POST or GET.

这是两种完全不同的方法,因此可能很难编写可重用的东西.本质上,一种是简单的旧 HTML 方法,而另一种需要更复杂一些和一些 Javascript.

It's two quite different approaches so may be difficult to write something reusable. Essentially one is a plain old HTML methodology whereas the other requires a a bit more sophistication and some Javascript.

这篇关于带刷新和不带刷新的 Angularjs 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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