简体   繁体   中英

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. 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. 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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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