0
我创建了一个简单的骨干脚本,这依赖于一个简单的api创建与laravel RESTful功能。包含Backbone脚本的html驻留在我的桌面和我的xampp本地主机上的服务器api上。骨干与laravel作为一个api不返回错误
上Laravel:
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$task = Task::find($id);
return $task;
}
的骨干:
(function(){
App = {
Models : {},
Views : {},
Collections : {}
};
App.Models.Task = Backbone.Model.extend({
defaults : {title : '', active : 0},
urlRoot : 'http://localhost/api/public/tasks'
});
var task = new App.Models.Task({id : 1});
task.fetch();
//task.set({title : 'new tite', active : 1});
//task.save();
})();
服务器侧缝是好的,在测试的原因返回正确的json对象,但是当我尝试运行骨干脚本我在开发控制台得到这个错误:
> XMLHttpRequest cannot load http://localhost/api/public/tasks/1. No
> 'Access-Control-Allow-Origin' header is present on the requested
> resource. Origin 'null' is therefore not allowed access
。 有什么问题?
听起来像是你有两个d不同的域名,一个用于骨干页面,另一个用于laravel api。你可以确保它们在同一个域上运行,或者[请参阅设置原始头文件的这个问题](http://stackoverflow.com/questions/1653308)。 – bejonbee