1

I have a simple html form in a coldfusion application. Here is the code:

<form id="form1" name="form1" method="post" action="myAngularApp/#/myapp/new">; 
<input name="data" type="hidden" id="hiddenField" value="<cfoutput>#form.data#</cfoutput>" /> 
</form> 
<script> document.form1.submit(); </script> 

The Url in 'Action' points to a different server that hosts an angular app (running on nodejs). Also I use full path including http (removed above for brevity) in Url. When I click submit, it goes to the other site but shows 'Cannot POST /' message. If I access the same link directly in a new browser window, the page loads fine. If I replace POST with GET method, then the destination page loads but immediately redirects the user to login page for authentication and when user comes back, the data posted (available as querystring) is lost. Angular app is a hybrid app (Angular version 4.4 and 1.6; node version 9.x). How do I make POST work? I am not using express. Most of the links I found while searching online show express examples but I dont use express. Do I need to use ngRoute? Since it's a hybrid app, I am not sure whether to use angular-route (ngRoute) or angular-router. If the destination page loads directly in browser, why does not it load when redirected from the other server?

Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66
J.Bowden11
  • 21
  • 2
  • Why was this down voted? – JBis May 21 '18 at 21:10
  • @Josh I did not downvote it, but I personally answered a lot of CORS-related questions and this one should help the asker: https://stackoverflow.com/questions/25845203/understanding-cors?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa I guess this might be the reason. – Lajos Arpad May 21 '18 at 21:11
  • 2
    @LajosArpad Thank you for appropriately responding. Boggles me why people find the need to down vote newbie questions without an explanation. We want to encourage not discourage newbies from asking questions. – JBis May 21 '18 at 21:17
  • @LajosArpad The `action` attribute posts without JavaScript. If there is no javascript involved in posting the form, then the same origin policy is not applicable. See [Cross Domain Form POSTing](https://stackoverflow.com/a/11425019/5535245). – georgeawg May 21 '18 at 21:30
  • 3
    This question doesn't make sense. How does a form POST to an AngularJS site? AngularJS is a client-side framework. – georgeawg May 21 '18 at 21:39
  • 1
    The prose includes, `When I click submit,` yet the code shows nothing to click. – Dan Bracuk May 21 '18 at 22:23
  • @Josh Thank you very much. I am a newbie and this is my second question only on this forum. I am surprised at the number of negative and discouraging comments from other users. Instead of trying to help, they start commenting on stupid things like the format of the question, the minor things not included in code for sake of brevity, etc. I think my question was very clear. If someone had an answer, they would have answer instead of commenting on the missing submit button. – J.Bowden11 May 22 '18 at 14:00
  • Coming back to my question, does any one know why GET works but POST doesn't? and how to make POST work? I believe the problem is at the receiving end which is an angular site running on top of node server. – J.Bowden11 May 22 '18 at 14:11
  • @J.Bowden11 If the problem is at the receiving end, please show the receiving code. It does not appear to be a problem with your html form. – Sam M May 24 '18 at 19:26

0 Answers0