If the site redirects to my target site with a form post, I want to be able to read the incoming data from the post request using angular 2 typescript. Is there a way to do it?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Basically it's not possible with just angular. Simply put this answer: How to read the post request parameters using javascript
However, depending on your server you have options; When parsing the request you could use a server side language to generate your index.html. e.g. a PHP file.
At this point you could print the post data into a script tag e.g. with PHP
<script type="text/javascript">
var somePostData = <?php echo $_POST['some_data']; ?>
</script>
Could that be something for you to work with? Of course you'd have to properly escape the data. then it would be accessible like:
window["somePostData"] in your angular code, or you define the type.