I am working on a simple Angular code to read JSON data from a specific API URL. When I access the URL , it returns the following JSON data:
Although the URL works fine when accessed through a browser, I'm facing issues while trying to read the same URL using Angular code.
/**
* Created by ZeroL on 27/05/2017.
*/
var myApp = angular.module('myApp', []);
myApp.controller('myController', function($scope, $http) {
var $seplink = "sepehr360.com/Flight/FlightSearchGrouped?str={"Browser":"TestAndroid","CookieGuid":"","CredentialPassword":"","CredentialUserName":"","CurencyType":"IRR","CurrentUICulture":"fa-ir","From":"SYZ","IntervalDay":0,"IsCancelAvail":false,"IsDirectContract":false,"IsFlightContinuous":false,"IsLogin":true,"IsOnlineSupport":false,"IsTour":false,"Language":"fa","PageSize":10,"Passenger":"","PassengerItem":"","RecordId":1,"SortOrder":1,"StartDate":"1396/3/15","To":"IKA,THR","UserHostAddress":"","UserInfoId":"","UserName":"Mobile360","getTwoWay":false}";
var $seplink1 = "data.json";
$http.get($seplink)
.success(function(response){
$scope.myData = response;
});
});
<html>
<head>
<script src="angular.min.js"></script>
<script src="js.js"></script>
</head>
<body ng-app="myApp" ng-controller="myController">
Search : <input title="search" type="text" value="" ng-model="search"/>
<table border=1>
<tr ng-repeat="data in myData.FlightList">
<td><img src="http://sepehr360.ir/{{data.AirLineImage}}" alt="ar"></td>
<td>{{data.AirLineTitle}}</td>
<td>{{data.FormatedPrice}}</td>
<td> <a href="http://sepehr360.com{{data.FlightItems[0].FlightInfo.AgencyAddress}}">get this ticket</a>
</td>
</tr>
</table>
</body>
</html>
Despite seeing results without any access info, I have managed to successfully save the URL data to a local file named 'data.js'. The code works perfectly with this setup. Can someone please guide me on how to efficiently read JSON data from the specified URL using HTTP? Your help is greatly appreciated. Thank you!