簡體   English   中英

$ http請求404找不到附加本地主機?

[英]$http Request 404 not found appending localhost?

我正在嘗試使用$ http和get請求調用api。 我找不到404,當我看電話時,它會將http:// localhost:3000 /附加到前面,這就是問題所在。 如何阻止它執行此操作? 我正在使用角度並注入$ http。

app.factory('videos', ['$http', function($http){



  function pullData(){
    $http.get("api.redtube.com/data=redtube.Videos.searchVideos&output=json&search=hard&tags[]=Teen&thumbsize=medium").success(function(response){
    o.videos.push(response)
    });
    }

    pullData()   // call the function to pull data from the API

    var o = {videos: []

    };

    return o; 

}])

問題是URL,而不是$ http提供程序。 您錯過了“?” 字符,指示數據是查詢字符串的一部分。 嘗試使用此代替:

app.factory('videos', ['$http', function($http){



function pullData(){
    $http.get("http://api.redtube.com/?data=redtube.Videos.searchVideos&output=json&search=hard&tags[]=Teen&thumbsize=medium").success(function(response){
    o.videos.push(response)
    });
    }

    pullData()   // call the function to pull data from the API

    var o = {videos: []

    };

    return o; 

}])

編輯:對於CORS問題,請嘗試使用JSONP

// Instead of
$http.get(...)
// use
$http.jsonp(...);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM