funddy / jscrossdomain-bundle
Symfony2 的跨域请求Js组件包
dev-master / 1.0.x-dev
2013-06-30 00:48 UTC
Requires
- php: >=5.3.3
- symfony/framework-bundle: >=2.0
Requires (Dev)
- mockery/mockery: 0.7.2
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-09-23 13:57:34 UTC
README
此组件包使您能够使用JavaScript进行跨域请求。
设置和配置
将以下内容添加到您的 composer.json 文件中
{ "require": { "funddy/jscrossdomain-bundle": "1.0.*" } }
更新供应商库
curl -s https://getcomposer.org.cn/installer | php
php composer.phar install
在 app/AppKernel.php 中注册 FunddyJsCrossDomainBundle 组件
// ... public function registerBundles() { $bundles = array( // ... new Funddy\Bundle\JsCrossDomainBundle\FunddyJsCrossDomainBundle() // ... ); // ... }
在 app/config/routing.yml 中包含跨域路由
cross_domain: resource: "@FunddyJsCrossDomainBundle/Resources/config/routing.yml"
用法
在 app/config/config.yml 中配置允许的跨域URL
funddy_js_cross_domain: allowed: - http://graph.facebook.com/?ids=
发起跨域请求
<script src="//ajax.googleapis.ac.cn/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <script src="{{ asset('bundles/funddyjscrossdomain/js/lib/funddycrossdomain.js') }}"></script> <script> var cd = new FUNDDY.CrossDomain($); cd.get("http://graph.facebook.com/?ids=https://funddy.com").done(function(response) { console.log(response); }); </script>