javascript - JSON response format is not correct (angularjs) -
i have problem json response when call youtube api angularjs :
code:
sc.factory('videoapi', ['$resource', function($resource) { return $resource( 'https://www.googleapis.com/youtube/v3/search', {callback: 'json_callback'}, { get: { method: 'get', params: { order: 'date', part: 'snippet', channelid: 'ucy8zyy7ysq80jw1ijo2bjva', type: 'video', key: '*** key ***' }, isarray : false, } } ); }]); sc.controller('scontroller', ['$scope','videoapi', function ($scope,videoapi) { videoapi.get().$promise.then(function(data) { console.log(data); // console.log(data); //for (i = 0; < data.length; i++) { //var question = editquestion(data[i].title, data[i].time, data[i].voteyes, data[i].voteno, true, data[i].num, data[i].ip); //questionlist.push(question); //} }); $scope.inputtest = "test"; }]);
response :
1: "c"102: "h"103: "q"104: "_"105: "m"106: "z"107: "w"108: "j"109: "s"110: "/"111: "1"112: "e"113: "g"114: "6"115: "t"116: "t"117: "t"118: "v"119: "f"120: "u"121: "g"122: "s"123: "l"124: "y"125: "j"126: "s"127: "7"128: "g"129: "m"130: "h"131: "u"132: "z"133: "x"134: "g"135: "r"136: "5"137: "m"138: "\"139: """140: """141: ","142: "↵"143: " "144: """145: "n"146: "e"147: "x"148: "t"149: "p"150: "a"151: "g"152: "e"153: "t"154: "o"155: "k"156: "e"157: "n"158: """159: ":"160: " "161: """162: "c"163: "a"164: "u"165: "q"166: "a"167: "a"168: """169: ","170: "↵"171: " "172: """173: "p"174: "a"175: "g"176: "e"177: "i"178: "n"179: "f"180: "o"181: """182: ":"183: " "184: "{"185: "↵"186: " "187: " "188: """189: "t"190: "o"191: "t"192: "a"193: "l"194: "r"195: "e"196: "s"197: "u"198: "l"199: "t"200: "s"201: """202: ":"203: " "204: "1"205: "1"206: ","207: "↵"208: " "209: " "210: """211: "r"212: "e"213: "
however when network tab in chrome correct format response :
// api callback json_callback({"kind": "youtube#searchlistresponse","etag": "\"no6qteg0-3shswieqlchq_ ....
do know why response format in data variable?
thanks in advance, have day :)
this solve problem :
return $resource( 'https://www.googleapis.com/youtube/v3/search', {callback: 'json_callback'}, { get: { method: 'jsonp', params: { order: 'date', part: 'snippet', channelid: 'ucy8zyy7ysq80jw1ijo2bjva', type: 'video', key: 'aizasybrmlzjy9p_hfgslkk6vzwkrhp3evuqlvk' }, isarray : false, } } );
the jsfiddle link :http://jsfiddle.net/nrg0hnx1/
Comments
Post a Comment