在 angularjs 中获取 URL 数据
Fetch URL data in angularjs
我需要从重定向 URL 中获取附加到 URL 的数据。以下是我的服务。我如何获得它?
paymentResponse.redirectPayment = function () {
//return $http.get(urlBase);
return $http({
method: 'POST',
url: urlBase + redirectAPI,
headers:{
'api_key': apiKey
},
data: {
"type":"redirect",
"_id":"id",
"currency":"EUR",
"amount":100,
"description": "This is a test",
"result_options": {
"notification_url": null,
"redirect_url": $location.protocol() + '://'+ $location.host() +':'+ $location.port() +'#/sucessresponse',
"cancel_url": $location.protocol() + '://'+ $location.host() +':'+ $location.port() +'#/scan',
"close_window": true
}
}
});
};
所以,现在,取消后,它会从我的第三方 api 重定向回 - 比如说 -
“http://localhost:9000/#/scan?section_id=test_id”。
现在,如何在我的 angular 应用程序中获取 "section_id=test_id"?
$location.search()
将为您提供一个包含所有查询参数的对象。
例如 url http://localhost:9000/#/scan?section_id=test_id
。 $location.search()
会给你下面的JS对象
{
'section_id': 'test_id'
}
详情见angular docs
我需要从重定向 URL 中获取附加到 URL 的数据。以下是我的服务。我如何获得它?
paymentResponse.redirectPayment = function () {
//return $http.get(urlBase);
return $http({
method: 'POST',
url: urlBase + redirectAPI,
headers:{
'api_key': apiKey
},
data: {
"type":"redirect",
"_id":"id",
"currency":"EUR",
"amount":100,
"description": "This is a test",
"result_options": {
"notification_url": null,
"redirect_url": $location.protocol() + '://'+ $location.host() +':'+ $location.port() +'#/sucessresponse',
"cancel_url": $location.protocol() + '://'+ $location.host() +':'+ $location.port() +'#/scan',
"close_window": true
}
}
});
};
所以,现在,取消后,它会从我的第三方 api 重定向回 - 比如说 - “http://localhost:9000/#/scan?section_id=test_id”。
现在,如何在我的 angular 应用程序中获取 "section_id=test_id"?
$location.search()
将为您提供一个包含所有查询参数的对象。
例如 url http://localhost:9000/#/scan?section_id=test_id
。 $location.search()
会给你下面的JS对象
{
'section_id': 'test_id'
}
详情见angular docs