如何在Angular 2 Typescript中读取表单发布数据? [英] How to read form post data in Angular 2 typescript?

查看:37
本文介绍了如何在Angular 2 Typescript中读取表单发布数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果该站点使用表单发布重定向到我的目标站点,则我希望能够使用angular 2打字稿从发布请求中读取传入的数据.有办法吗?

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?

推荐答案

基本上,仅凭角度是不可能的.只需简单地给出以下答案:如何使用javascript读取发布请求参数

Basically it's not possible with just angular. Simply put this answer: How to read the post request parameters using javascript

但是,根据您的服务器,您可以选择;解析请求时,您可以使用服务器端语言来生成index.html.例如一个PHP文件.

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.

此时,您可以将帖子数据打印到脚本标签中,例如使用PHP

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"],或定义类型.

window["somePostData"] in your angular code, or you define the type.

这篇关于如何在Angular 2 Typescript中读取表单发布数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆