带有和不带有刷新的AngularJS表单

编程入门 行业动态 更新时间:2024-10-10 05:25:33
本文介绍了带有和不带有刷新的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.

听起来您正在/home通过HTTP POST或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表单

本文发布于:2023-10-30 07:31:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542189.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   AngularJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!