2016-11-15 24 views
1

Im trying to execute a like POST request with a in angular. The url gets filled in correctly as you can see<a href> Post request always returns to wrong URL Angular

<a href="http://dressfriends.app/en/like/product/1006" target="_parent" df-like-product="" class="icon-like trigger animated v-a-m active" data-id="1006" data-type="product" ng-class="{active:product.liked_by_user}"></a>

In the code it looks like this

<a href="##product.like_url##" target="_parent" df-like-product class="icon-like trigger animated v-a-m" data-id="##product.id##" data-type="product" ng-class="{active:product.liked_by_user}"></a>

But everytime it gives a 405 method not allowed (http://dressfriends.app)と戻り私は角なしでPHPで正確なsamethingを行うと、これは誰でもアイデア

<a href="{{ $product->present()->likeUrl }}" df-like-product class="icon-like trigger animated v-a-m {{ ($currentUser and $product->hasLiked($currentUser->id)) ? 'active' : '' }}" data-id="{{ $product->id }}" data-type="product"></a>

に動作しますか?

+0

...

https://docs.angularjs.org/api/ng/service/ $ HTTP

https://www.sitepoint.com/creating-crud-app-minutes-angulars-resource/ を。それにPOSTする場合は、フォームまたはajaxを使用する必要があります。 – aynber

+0

しかし別のビューではPHP laravel bladeを使用していますが、hrefで動作しますか?違いは何ですか? – Janvdt

+0

そのコードがなければ、私は言うことができませんでした。または、GETルートが定義されている可能性があります。 – aynber

答えて

0

PHPではない角度。これを解決するため。いくつかのサービスを利用する必要があります。最も一般的なのは$ httpと$ resourceです。あなたは$ HTTPサービスを選択した場合の

、あなたはこのようなものがありますコントローラにsomefile.html

を行う必要があります)

$ scope.someFunction =関数( {

$ http.post(URL、データ、コンフィグ) .then( 機能(応答){// 成功コールバック }、 関数(応答){ //失敗のコールバック } ); }

私はこのようなためのチュートリアル見つけようとすることをお勧めいたします: `href`リンクは常にGET経由で取得され