I created an simple Backbone script wich relies on a simple api created with laravel RESTful capabilities. The html containing Backbone script resides on my desktop and the server api on my xampp localhost.
on Laravel :
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$task = Task::find($id);
return $task;
}
on Backbone :
(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();
})();
The server side seams to be ok, cause on testing returns the proper json object, but when i try to run the Backbone script i get this error in dev console :
> 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
. What could be the problem ???