【问题标题】:how to get form data params in headers using angularjs?如何使用 angularjs 在标题中获取表单数据参数?
【发布时间】:2016-08-06 12:30:20
【问题描述】:

我使用 $http post 成功后,我在网络中获得了标头,它由 General、Request Headers、Response Headers、Form Data 组成。

如果我使用 headers() 我得到了响应头,但是我如何获得表单数据对象。

 $http({
        method: "POST",
        url: "http://localhost/demoPaymentGatway/index.html",
        headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        'X-Requested-With': 'XMLHttpRequest'
                    }
                }).success(function(data, status, headers, config) {
                    console.log(headers());
                    console.log();
                    }).error(function(r4) {
                        console.log(headers);

                });

标题:

General:

 Request URL:http://localhost/demoPaymentGatway/index.html
 Request Method:POST
 Status Code:200 OK
 Remote Address:[::1]:80

Response Headers: 

 Accept-Ranges:bytes
 Connection:Keep-Alive
 Content-Length:1856
 Content-Type:text/html
 Date:Sat, 06 Aug 2016 12:17:17 GMT
 ETag:"740-5396528fb715b"
 Keep-Alive:timeout=5, max=100
 Last-Modified:Sat, 06 Aug 2016 11:05:25 GMT
 Server:Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.37


 Request Headers:
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:700
Content-Type:application/x-www-form-urlencoded
Cookie:PHPSESSID=el7a4qk56sv4ujo4kou0qf43k4
Host:localhost
Origin:null
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,  like Gecko) Chrome/52.0.2743.82 Safari/537.36

Form Data:
mihpayid:114256656
mode:
status:failure
unmappedstatus:userCancelled
key:WHlKGc
txnid:264997125205
amount:1.0
addedon:2016-08-06 17:47:58
productinfo:productitem
firstname:vasu

请帮助我如何使用 $http,$resource 获取此表单数据

【问题讨论】:

  • 我是否理解正确,您基本上是想在实际提出请求之前获取表单数据并对其进行操作,还是希望它在成功回调本身中?
  • 是的,我想获取表单数据。但是表单数据来自支付网关的重定向 url。根据成功/失败,我想解雇订单。
  • 请告诉我如何获取这个唯一的表单数据...

标签: angularjs


【解决方案1】:

如果您需要在成功回调中访问在 POST 请求中发送的表单数据,您需要查看 config.data 属性。

$http({
        method: "POST",
        url: "http://localhost/demoPaymentGatway/index.html",
        headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        'X-Requested-With': 'XMLHttpRequest'
                    }
                }).success(function(data, status, headers, config) {
                    //This is the post data that was originally sent
                    console.log(config.data);
                    }).error(function(r4) {
                        console.log(headers);

                });

参考请见this link

【讨论】:

  • 对不起,伙计。我得到了未定义的。
  • 配置用于请求的对象。
  • 从支付网关重定向后。支付网关将数据发布到localhost/demoPaymentGatway/index.html,即标头。
  • 是的,正确的配置是您在发送请求时设置的对象。但是,成功回调中的配置对象确实包含您发送的原始数据....或者我可能一开始不理解您的查询...我们可以将其移至聊天
猜你喜欢
  • 2018-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多