FormSubmit非常适合轻松提交轻量级表单。我在我的 Angular 应用程序中使用它并尝试使用 POST 表单HttpClient,但我似乎无法正确处理。我猜我的 POST url 是错误的,但我不知道正确的方法是什么。这是我的onSubmit功能: onSubmit() { this.submitted = true; if (this.contactForm.invalid) { return; } else { this.formSubmit.sendForm(JSON.stringify(this.contactForm.value)); } }这里的HttpClient服务:import { Injectable } from '@angular/core';import { HttpClient } from '@angular/common/http';@Injectable({ providedIn: 'root'})export class FormsubmitService { constructor( public httpClient: HttpClient ) { } sendForm(formData) { console.log('Form Data:', formData); this.httpClient.post('https://formsubmit.io/send/<TOKEN HERE>', formData) .subscribe( (response) => console.log("Response:", response), (error) => console.log("Error:", error)); }}错误响应:
1 回答
慕丝7291255
TA贡献1859条经验 获得超6个赞
再会!你能试试吗?
onSubmit() {
this.submitted = true;
if (this.contactForm.valid) {
const formData = new FormData();
const { value } = this.contactForm;
for (const key in value) {
formData.append(key, value[key]);
}
this.formSubmit.sendForm(formData);
}
}
添加回答
举报
0/150
提交
取消