如何使用 JS/Jquery 读取 post 参数
How to read post parameters using JS/Jquery
我已经将支付网关与基于 Java 的 Web 应用程序集成在一起
现在,在成功和失败的交易之后,
PG 相应地重定向到带有表单数据的 html 页面 failure.html、success.html。
我如何阅读和使用这些数据。
我不知道,需要帮助的人。
General
Request URL:http://www.educationxpress.in/failure.html
Request Method:POST
Status Code:200 OK
Remote Address:43.242.215.132:80
Response Headers
view source
Accept-Ranges:bytes
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:2461
Content-Type:text/html
Date:Mon, 21 Mar 2016 11:44:23 GMT
ETag:W/"7124-1458556448000"
Last-Modified:Mon, 21 Mar 2016 10:34:08 GMT
Server:Apache-Coyote/1.1
Vary:Accept-Encoding
Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0. 8
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:1087
Content-Type:application/x-www-form-urlencoded
Host:www.xywevbsite.in
Origin:null
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Form Data
view source
view URL encoded
mihpayid:550690310
mode:DC
status:failure
unmappedstatus:failed
txnid:f63fdb227b24393099dc
amount:45.0
addedon:2016-03-21 17:12:37
productinfo:Rabbit
firstname:Mohit
需要有关如何阅读此回复的帮助????
客户端代码无法访问请求中用于加载正在执行客户端代码的页面的大部分数据,包括 POST 数据。
您需要改用服务器端代码。
您无法在客户端读取 POST 数据,但您可以在使用 localStorage:
提交表单时将其保存在本地
<form onSubmit="formSubmitted()">
<input type="text" id="firstname" name="firstname" />
...
</form>
<script type="text/javascript>
function formSubmitted() {
localStorage.setItem('firstname', document.getElementById('firstname').value);
}
</script>
您也可以使用任何服务器端语言来获取它:
var firstname = "<?php echo $_POST['firstname']; ?>";
当与支付网关集成时,或者通常当您收到基于服务器 response.Simply 的
重定向 URL 时,将您的 URL 映射到控制器或 Servlet 中。
通过这种方式您可以访问请求参数并根据参数和其他
信息您可以重定向页面。
示例:
我提供了 http://www.localhost.in/failure
在您的控制器
中 url 上方映射
@RequestMapping(value = "/failure.do", method = RequestMethod.POST)
public void pgResponse(@RequestBody ResonseBean bean, HttpServletRequest request, HttpServletResponse response )
{
try
{
// Here you can extract the parameters from POST request.
String amount = (String) request.getParameter("amount");
String addedon = (String) request.getParameter("addedon");
String productinfo = (String) request.getParameter("productinfo");
String firstname = (String) request.getParameter("firstname");
// Do you business here
// Redirect when you're done
}
catch ( Exception e )
{
}
}
或者您可以在不使用 Spring MVC、Spring Boot.
时简单地绑定一个 Servlet
在JSP环境中,
只需在 jsp page.For 中使用 scriptlet 示例:
<%
String amount = (String) request.getParameter("amount");
String addedon = (String) request.getParameter("addedon");
String productinfo = (String) request.getParameter("productinfo");
String firstname = (String) request.getParameter("firstname");
%>
<script type="javascipt">
// Get java variable value in js
var amount = <%=amount %>;
var addedon = <%=addedon%>;
var productinfo = <%=productinfo %>;
var firstname = <%=firstname %>;
</script>
这个问题有多种解决方法,它取决于您使用的堆栈。
我已经将支付网关与基于 Java 的 Web 应用程序集成在一起 现在,在成功和失败的交易之后, PG 相应地重定向到带有表单数据的 html 页面 failure.html、success.html。 我如何阅读和使用这些数据。 我不知道,需要帮助的人。
General
Request URL:http://www.educationxpress.in/failure.html
Request Method:POST
Status Code:200 OK
Remote Address:43.242.215.132:80
Response Headers
view source
Accept-Ranges:bytes
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:2461
Content-Type:text/html
Date:Mon, 21 Mar 2016 11:44:23 GMT
ETag:W/"7124-1458556448000"
Last-Modified:Mon, 21 Mar 2016 10:34:08 GMT
Server:Apache-Coyote/1.1
Vary:Accept-Encoding
Request Headers
view source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0. 8
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:1087
Content-Type:application/x-www-form-urlencoded
Host:www.xywevbsite.in
Origin:null
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Form Data
view source
view URL encoded
mihpayid:550690310
mode:DC
status:failure
unmappedstatus:failed
txnid:f63fdb227b24393099dc
amount:45.0
addedon:2016-03-21 17:12:37
productinfo:Rabbit
firstname:Mohit
需要有关如何阅读此回复的帮助????
客户端代码无法访问请求中用于加载正在执行客户端代码的页面的大部分数据,包括 POST 数据。
您需要改用服务器端代码。
您无法在客户端读取 POST 数据,但您可以在使用 localStorage:
提交表单时将其保存在本地<form onSubmit="formSubmitted()">
<input type="text" id="firstname" name="firstname" />
...
</form>
<script type="text/javascript>
function formSubmitted() {
localStorage.setItem('firstname', document.getElementById('firstname').value);
}
</script>
您也可以使用任何服务器端语言来获取它:
var firstname = "<?php echo $_POST['firstname']; ?>";
当与支付网关集成时,或者通常当您收到基于服务器 response.Simply 的
重定向 URL 时,将您的 URL 映射到控制器或 Servlet 中。
通过这种方式您可以访问请求参数并根据参数和其他
信息您可以重定向页面。
示例:
我提供了 http://www.localhost.in/failure
在您的控制器
@RequestMapping(value = "/failure.do", method = RequestMethod.POST)
public void pgResponse(@RequestBody ResonseBean bean, HttpServletRequest request, HttpServletResponse response )
{
try
{
// Here you can extract the parameters from POST request.
String amount = (String) request.getParameter("amount");
String addedon = (String) request.getParameter("addedon");
String productinfo = (String) request.getParameter("productinfo");
String firstname = (String) request.getParameter("firstname");
// Do you business here
// Redirect when you're done
}
catch ( Exception e )
{
}
}
或者您可以在不使用 Spring MVC、Spring Boot.
时简单地绑定一个 Servlet在JSP环境中,
只需在 jsp page.For 中使用 scriptlet 示例:
<%
String amount = (String) request.getParameter("amount");
String addedon = (String) request.getParameter("addedon");
String productinfo = (String) request.getParameter("productinfo");
String firstname = (String) request.getParameter("firstname");
%>
<script type="javascipt">
// Get java variable value in js
var amount = <%=amount %>;
var addedon = <%=addedon%>;
var productinfo = <%=productinfo %>;
var firstname = <%=firstname %>;
</script>
这个问题有多种解决方法,它取决于您使用的堆栈。