简体   繁体   English

角形默认行为

[英]Angular Form default behavior

I'm implementing an app that do a submit post with a form. 我正在实现一个使用表单提交帖子的应用程序。 In response, I receive an URL and some required data. 作为回应,我收到一个URL和一些必需的数据。 With both that, I'm creating a new form in the controller, passing the url in the action tag, and creating inputs based in the data received. 通过这两种方式,我将在控制器中创建一个新表单,在action标签中传递url,并基于接收到的数据创建输入。 I then try do submit the form programmatically. 然后,我尝试以编程方式提交表单。 That should redirect me to a new page with the data sent. 那应该将我重定向到发送数据的新页面。 But the action isn't executed. 但是该动作未执行。

How should I manage this type of action? 我应该如何处理这类行动? As I NEED to be redirected after submitting the form. 由于我需要在提交表格后进行重定向。

How I am creating the new form and submitting it: resp is the response from the first post. 我如何创建新表单并提交它:resp是第一篇文章的回复。

var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('action',resp.data.url);
f.setAttribute('target','_blank');

 for (var prop in resp.data.dadosForm) {
     var i = document.createElement("input"); //input element, text
     i.setAttribute('type',"hidden");
     i.setAttribute('name',prop);
     i.setAttribute('value',resp.data.dadosForm[prop]);
     f.appendChild(i);
 }

 var s = document.createElement("input"); //input element, Submit button
 s.setAttribute('type',"submit");
 s.setAttribute('class',"button button-block button-balanced");
 s.setAttribute('value',"Iniciar Pagamento");
 s.setAttribute('ng-submit', payzenSubmit );
 f.appendChild(s);
 //document.getElementsByClassName('initPayment')[0].appendChild(f);

 f.submit();   

I'm not quite sure what you're trying to achive with your code, but you might need to add the form to the document before you attempt to submit it. 我不太确定您要用代码实现什么,但是您可能需要在提交表单之前将表单添加到文档中。 so before the f.submit() , you could try adding in document.body.appendChild(f); 因此,在f.submit()之前,您可以尝试添加document.body.appendChild(f); f.submit()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM