Angular 2/4:如何在第一次 ajax 提交的回调中通过组件发布 HTML 表单(非 ajax)? [英] Angular 2 / 4 : How to POST HTML form (Not ajax) thru component on callback of 1st ajax submit?
问题描述
我想通过以老式方式(非 Ajax)发布输入字段来将表单提交到外部站点,它也提交了,但 Angular 在跳转到外部页面之前在控制台中给了我错误.
I want to submit form to external site by POSTing the input fields in old school way(non Ajax) , it submits too but Angular giving me error in console before jumping to external page.
我在 HTML(模板)中使用了以下代码
I used following code in HTML(template)
<form (submit)="onSubmit($event)" method="POST" [formGroup]="form" *ngIf='form' action="https://www.sandbox.paypal.com/cgi-bin/webscr" >
在组件中
onSubmit(obj: any) {
if (!this.form.valid) {
this.helper.makeFieldsDirtyAndTouched(this.form);
} else {
this.loader = true;
// save data in online_payment_ipn
this.paymentService.saveOnlinePaymentIpn({}, 'paypal')
.subscribe(response => {
obj.target.submit();
}, (err: any) => {
this.loader = false;
this.helper.redirectToErrorPage(err.status);
});
}
}
现在首先这个表单通过普通的响应式表单 post(ajax) 将数据保存在我的站点中.现在之后,我以旧的提交表单的方式将整个表单像贝宝一样发布到第 3 方,但我得到了
Now first this form saves data in my site via normal reactive form post(ajax). Now after that I post to 3rd party like paypal whole form in Old way of submitting form but I am getting
表单提交被取消,因为表单未连接
感谢任何帮助.@H.B.谢谢
Any help is appreciated. @H.B. Thanks
推荐答案
您可能应该使用 onSubmit($event)
然后将事件取消到您的自定义逻辑.您可以通过 event.target
访问表单.在角度绑定中传入 this
可能只是行不通,我可能弄错了.
You probably should use onSubmit($event)
and then cancel the event to your custom logic. You can access the form via event.target
. Passing in this
in an angular binding probably just does not work, i might be mistaken.
这篇关于Angular 2/4:如何在第一次 ajax 提交的回调中通过组件发布 HTML 表单(非 ajax)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!