Emberjs 2 删除 CORS 和 CSP
Emberjs 2 remove CORS and CSP
我正在尝试 EmberJs 2,发现发出 Ajax 请求时出现问题。在Whosebug上看了很多问题,还是无法解决问题。
我从 http://localhost:4200 and my API server(PHP) is in http://localhost 访问 emberapp。下面是控制台的屏幕截图。
我应该怎么做?你能帮帮我吗?
提前致谢。
routes/users.js
import Ember from 'ember';
export default Ember.Route.extend({
model(){
console.log($.getJSON('http://localhost/api'));
}
});
environment.js:
module.exports = function(environment) {
var ENV = {
/*......*/
contentSecurityPolicy:{
'connect-src':" 'self' http://localhost ",
'font-src' : " 'self' http://localhost "
}
/*......*/
};
这是在 PHP localhost/api/index.php:
<?php header("Access-Control-Allow-Origin: *");
$array = array(
'name'=>"Firstname",
'lastname' => 'Lastname',
'age'=>'23'
);
echo json_encode($array);
ember server --proxy http://localhost:80
将代理所有 AJAX 到该地址的请求。
我正在尝试 EmberJs 2,发现发出 Ajax 请求时出现问题。在Whosebug上看了很多问题,还是无法解决问题。 我从 http://localhost:4200 and my API server(PHP) is in http://localhost 访问 emberapp。下面是控制台的屏幕截图。
我应该怎么做?你能帮帮我吗?
提前致谢。
routes/users.js
import Ember from 'ember';
export default Ember.Route.extend({
model(){
console.log($.getJSON('http://localhost/api'));
}
});
environment.js:
module.exports = function(environment) {
var ENV = {
/*......*/
contentSecurityPolicy:{
'connect-src':" 'self' http://localhost ",
'font-src' : " 'self' http://localhost "
}
/*......*/
};
这是在 PHP localhost/api/index.php:
<?php header("Access-Control-Allow-Origin: *");
$array = array(
'name'=>"Firstname",
'lastname' => 'Lastname',
'age'=>'23'
);
echo json_encode($array);
ember server --proxy http://localhost:80
将代理所有 AJAX 到该地址的请求。