AngularJS - $资源不同的URL为GET和POST [英] AngularJS - $resource different URL for Get and Post

查看:194
本文介绍了AngularJS - $资源不同的URL为GET和POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$资源是真棒提供了非常方便的方式来处理Web服务。
如果有什么GET和POST都以不同的URL进行?

$resource is awesome providing very convenient way to handle web services. What if GET and POST have to be performed on different URLs?

例如,GET网址是的http://本地主机/ pleaseGethere /:ID
和POST网址为的http://本地主机/ pleasePosthere 不带任何参数

For example, GET URL is http://localhost/pleaseGethere/:id and POST URL is http://localhost/pleasePosthere without any parameter

推荐答案

您应该能够揭露URL作为参数。我能做到这一点:

You should be able to expose the URL as a parameter. I was able to do this:

$provide.factory('twitterResource', [
    '$resource',
    function($resource) {
        return $resource(
            'https://:url/:action',
            {
                url: 'search.twitter.com',
                action: 'search.json',
                q: '#ThingsYouSayToYourBestFriend',
                callback: 'JSON_CALLBACK'
            },
            {
                get: {
                    method: 'JSONP'
                }
            }
        );
    }
]);

然后你就可以覆盖在你的 GET 调用的URL。

一个需要注意我真的我简短的测试中发现的是,如果我包括 HTTP:URL字符串// ,它没有工作。我没有得到一个错误信息。它只是没有采取任何行动。

The one caveat I found during my REALLY brief testing was that if I included http:// in the URL string, it didn't work. I didn't get an error message. It just did nothing.

这篇关于AngularJS - $资源不同的URL为GET和POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆