I use Angular in both websites. I have a first website with a JSON in a controller. I need to send it to another website's controller.
Question :
The following code working good as far i don't send special characteres in the JSON like a &
who will of course broke my url ( and of course the url length limitation )
Example of JSON who broke my code : {"recordedby":"mackee&","year":2016}
how can i send special caracteres like &
or /
without breaking the url ?
I looked for a solution to send data as post but i don't find anything.
What i do now :
In first website controller :
angular.module('site1').controller('site1Controller', ['$scope',
function($scope) {
...
$scope.createEditLink =function(){
var query = encodeURIComponent(JSON.stringify(jsonToSend));
var url = host +"/edit/query="+query;
return url ;
}
...
}
]);
In first website view :
<a ng-href="{{createEditLink()}}" target="_blank">
edit
</a>
The JSON To send :
{"filtered":{"filter":{"and":[{"or":[{"regexp":{"recordedby":".*mackee*.*"}},{"term":{"recordedby":"mackee*","_cache":false}}]}]}}}
so on click it open this link :
http://host/edition/query={%22filtered%22:{%22filter%22:{%22and%22:[{%22or%22:[{%22regexp%22:{%22recordedby%22:%22.*mackee*.*%22}},{%22term%22:{%22recordedby%22:%22mackee*%22,%22_cache%22:false}}]}]}}}
In the second website's controller :
angular.module('site2').controller('site2Controller', ['$scope','$routeParams',
function($scope,$routeParams) {
function myUrlToArray(url) {
var paramsFormatted = {};
var paramstmp = decodeURI(url).split("&");
for (var index = 0; index < paramstmp.length; ++index) {
var tmp = paramstmp[index].split("=");
paramsFormatted[ tmp[0] ] = tmp[1];
}
return paramsFormatted;
}
$scope.urlParams = myUrlToArray($routeParams.params);
var myJson = JSON.parse(decodeURIComponent($scope.urlParams["query"]));
....
}
]);
Any suggestions are welcomed.