如何使用JavaScript将值从一个打印到另一个 [英] How can I print values from one to another using JavaScript

查看:77
本文介绍了如何使用JavaScript将值从一个打印到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JavaScript将值打印到另一个



我有两页 index.html & indexMailer.html ,我想使用post方法将 index 页面的值发送到 indexMailer 页面。



我已成功使用get方法执行此操作,但使用post方法我不能。

请帮帮我......!

解决方案

如果您有可以将变量传递给JavaScript的服务器端语言(PHP,ASP.NET,...),则只能从JavaScript访问POST值。如果你没有服务器端语言,那么不幸的是,这是不可能的。



如果你使用PHP,你可以传递这样的POST值:

 <   script     type   =  text / javascript >  
var postValues =<?php echo json_encode (

_POST); ?取代;
// 现在访问如下值:postValues [name]
// 请注意,至少需要PHP版本5才能使用json_encode。
< / script >



如果您使用ASP.NET,则可以传递POST值,如下所示:

 <   script    类型  =  text / javascript  >  
var postValues =<%= new System.Web.Script.Serialization.JavaScriptSerializer()。Serialize(Request .Form.AllKeys.ToDictionary(k => k,k => Request.Form [k]))%> ;;
< / script >


How can I print values from one to another using JavaScript

I have two page index.html & indexMailer.html, I want to sent value from index page to indexMailer page using post method.

I have succeed to do this using get method, but using post method I can't.
Please help me...!

解决方案

POST values can only be accessed from JavaScript if you have a server-side language (PHP, ASP.NET, ...) that can pass the variables to JavaScript. If you have no server-side language, then unfortunately, it is not possible.

If you use PHP, you can pass the POST values like this:

<script type="text/javascript">
var postValues = <?php echo json_encode(


_POST); ?>; // Now access a value like this: postValues["name"] // Note that you'll need at least PHP version 5 to use "json_encode". </script>


If you use ASP.NET, you can pass the POST values like this:

<script type="text/javascript">
    var postValues = <%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Request.Form.AllKeys.ToDictionary(k => k, k => Request.Form[k])) %>;
</script>


这篇关于如何使用JavaScript将值从一个打印到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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