Forums

POST from the Client browser

tshirley 08 Nov, 2017
Hi,

I need to make a POST request to a third party site from the Client browser rather than the server. This is so that the third party can receive some data and then place a cookie in the client browser to avoid some repetitive authentication.

The requirement is quite basic - I want to make a POST to a url with a parameter which consists of three data items, which would be a json encoded string.

Having never done this before, I had a look at Javascript and there are ways to do it though I'm not sure how I would execute the JS code. There is also AJAX

I also noticed that the HTML (Render Form) Action has some options that could be relevant in this case, and perhaps there is a way to achieve what I want from there. Is there any tutorial which will help me to understand how to use the options in this Action?

Cheers

Tim
GreyHead 08 Nov, 2017
Hi Tim,

If you need to do this from the browser then it has to be done with JavaScript - see the jQuery post() method. You can run your script from a Load JavaScript action before the HTML (Render form) action.

Bob
tshirley 10 Nov, 2017
Thanks Bob,
Hi Bob

I have now a form which looks like this:

<!DOCTYPE html>
<body>
  <form name="myForm" method="post">
     <button type="submit" onclick="submitForm(); return false">POST_to_weather</button>
  </form>

<script type="text/javascript">
function submitForm()
{
   var form = document.forms['myForm'];
   form.action = 'https://mydomain.com';
   var el = document.createElement("input");
   el.type = "hidden";
   el.name = myparam;
   el.value = jQuery('#sk').val();
   form.appendChild(el);
   document.body.appendChild(form);
   form.submit();
}
</script>
</body>
</html>


And I have a field existing in the form, with a field ID of "sk".

The form does post to the target when the button is clicked but the parameter myparam isn't posted. I have tried a few different ways but no luck. Can you see what I have done wrong?

Cheers
Tim
GreyHead 15 Nov, 2017
Hi Tim,

That appears to be a completely separate html page - as you don't load jQuery in it I doubt that anything will work.

I think that all you need is a script snippet that is run when the from page has loaded to read the data value and send it.

Bob
tshirley 16 Nov, 2017
Hi Bob,

I was making this way too complicated. I solved the problem with a simple hidden html form which posts the data from a Custom Code action.

Many thanks and sorry to have troubled you with something that was in fact quite trivial.

Cheers

Tim
This topic is locked and no more replies can be posted.