简体   繁体   English

angularjs http获取请求faild加载网址

[英]angularjs http get request faild loading url

i have simple angular code to reading json api from url : http://sepehr360.com/Flight/FlightSearchGrouped?str= {%22Browser%22:%22TestAndroid%22,%22CookieGuid%22:%22%22,%22CredentialPassword%22:%22%22,%22CredentialUserName%22:%22%22,%22CurencyType%22:%22IRR%22,%22CurrentUICulture%22:%22fa-ir%22,%22From%22:%22SYZ%22,%22IntervalDay%22:0,%22IsCancelAvail%22:false,%22IsDirectContract%22:false,%22IsFlightContinuous%22:false,%22IsLogin%22:true,%22IsOnlineSupport%22:false,%22IsTour%22:false,%22Language%22:%22fa%22,%22PageSize%22:10,%22Passenger%22:%22%22,%22PassengerItem%22:%22%22,%22RecordId%22:1,%22SortOrder%22:1,%22StartDate%22:%221396/3/15%22,%22To%22:%22IKA,THR%22,%22UserHostAddress%22:%22%22,%22UserInfoId%22:%22%22,%22UserName%22:%22Mobile360%22,%22getTwoWay%22:false} 我有简单的角度代码从URL读取json api: http ://sepehr360.com/Flight/FlightSearchGrouped?str = {%22Browser%22:%22TestAndroid%22,%22CookieGuid%22:%22%22,%22CredentialPassword% 22:%22%22%22CredentialUserName%22:%22%22%22CurencyType%22:%22IRR%22%22CurrentUICulture%22:%22FA-IR%22%22From%22:%22SYZ%22% 22IntervalDay%22:0,%22IsCancelAvail%22:假,%22IsDirectContract%22:假,%22IsFlightContinuous%22:假,%22IsLogin%22:真,%22IsOnlineSupport%22:假,%22IsTour%22:假,%22Language %22:%22FA%22%22PageSize%22:10,%22Passenger%22:%22%22%22PassengerItem%22:%22%22%22RecordId%22:1,%22SortOrder%22:1,% 22StartDate%22:%3分之221396/ 15%22%22To%22:%22IKA,THR%22%22UserHostAddress%22:%22%22%22UserInfoId%22:%22%22%22UserName%22: %22Mobile360%22%22getTwoWay%22:假}

when i get this url by browser its work and give json data and i use this angular code to reading that url 当我通过浏览器得到这个URL它的工作并给出json数据,我使用这个角度代码来读取该URL

 /** * 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 thicket</a> </td> </tr> </table> </body> </html> 

and i see result with no access info but i try to save url data to data.js on local and code works very well please help me to reading json data from this url with http thanks 并且我看到没有访问信息的结果,但我尝试将url数据保存到本地的data.js并且代码工作得非常好请帮我从这个url中读取json数据用http谢谢

Have you tried using JSON.stringify on the JSON object and then concatenating it to the URL? 您是否尝试在JSON对象上使用JSON.stringify,然后将其连接到URL?

Like this: 像这样:

var $seplink = "simpleUrl";

var $jsonObject = JSON.stringify(jsonObject);

var URL = $sepLink + $jsonObject;

$http.get($seplink)
    .success(function(response){
        $scope.myData = response;
    }

Also, could you add information about the error you're getting? 另外,您是否可以添加有关您遇到的错误的信息?

You have an invalid string literal 您的字符串文字无效

"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}"

You need to use single quotes ( ' ) to encapsulate the literal: 您需要使用单引号( ' )来封装文字:

'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}'

Or escape the double quotes ( " ) that appear in the string 或者转义出现在字符串中的双引号( "

"sepehr360.com/Flight/FlightSearchGrouped?str={\"Browser\":\"TestAndroid\"......"

Also, the JavaScript code that you've posted is invalid. 此外,您发布的JavaScript代码无效。 You have two closing curly brackets ( }} ) characters after the controller declaration that are out of place. 在控制器声明之后,您有两个结束的大括号( }} )字符不合适。

您需要存储包含服务器返回的实际数据的响应数据。

$scope.myData = response.data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM