0

Using the following function to post the param value to a certain url (running on another server):

function yourfunction(url, params) {
    var form = $('<form action="' + url + '" method="post">' +
            '<input type="text" name="api_url" value="' + params + '" />' +
            '</form>');
    $('body').append(form);
    $(form).submit();   
}

Using this I am able to get redirected page but how to get params value on the same?

falsetru
  • 357,413
  • 63
  • 732
  • 636
gjosh
  • 135
  • 3
  • 18
  • Possible duplicate of: http://stackoverflow.com/questions/298745/how-do-i-send-a-cross-domain-post-request-via-javascript. – jbr Aug 06 '13 at 07:24

1 Answers1

0

To read post values you need some server side scripting like PHP In PHP your can read this value as:

$api_url = $_POST['api_url'];

You can not read POST data in Javascript. POST data is data that is handled server side. And Javascript is on client side. So there is no way you can read a post data using JavaScript.

Else You can use GET method instead of POST. So that all the values are passed in URL and you can access them through Javascript.

But this method is not safe and not recommend by any one as all the values expose and can be altered.

Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
  • Hi, I am using javascript at recieving end need to include this feature in onLoad function. How to include php in javascript to get param value. – gjosh Aug 06 '13 at 06:53
  • http://stackoverflow.com/questions/1409013/how-to-read-the-post-request-parameters-using-javascript – Suresh Kamrushi Aug 06 '13 at 06:56
  • If this is the case then how two javascripts running on different servers communicate. I need to send message from my website to another on redirect from mine. – gjosh Aug 06 '13 at 07:07