title: Backbone in sails.js
body: <p>I am creating a site using sails and passport for authentication purposes. I've got problems when it come to the use of Jquery and backbone in my code though. It seems that both are down when i tried to use them with sails. What I am trying to do, after user authentication I route the user to home page where all the scripts exists. I put all .js files in the layout.ejs, for exapmle:</p>
  
  <pre><code>&lt;link rel="stylesheet" href="styles/bootstrap-theme.min.css"&gt;
  &lt;script type="text/javascript" src="js/jquery.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Most of css and js files works, but I run into problems with backbone and jquery (and jquerymobile). I am using  jQuery 1.10.2 and backbone 1.1.0. Any idea what might be wrong?</p>
  
  <p>In backbone code, I a trying to make Ajax requests via a php file.</p>
  
  <pre><code>   var ProfileList = Backbone.Collection.extend({
  
                      model: ProfileModel,
                      url: 'data.php'
      });   
  </code></pre>
  
  <p>What exactly i ve got to do? To add url in routes? Or where should I place data.php file?</p>
  
  <p>EDIT:I ve changed gruntfile.js putting jquery at the top and works fine. Now the problem remains the backbone. I am guessing that my troubles arises since I request access to different domains using passport and backbone. When I am requesting data with data.php I am calling the following jquery code:</p>
  
  <pre><code>xhr.send( ( s.hasContent &amp;&amp; s.data ) || null ): jquery.js (line 8706)   
  </code></pre>
  
  <p>This is an Ajax XMLHttpRequest send request <a href="http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp" rel="nofollow">http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp</a>. I generally try to request data from two domains localhost and localhost:1337, so a cross domain issue arises.
  I ve found that cors(cross origin recource sharing) can handle this issue. Any idea how to allow cors in sails.js??   </p>
  
  <p>EDIT: In the route.js file I turn in homepage cors to true:</p>
  
  <pre><code>'/secondscreen': {
  view: 'secondsocialscreen/index',
  cors: true  
  </code></pre>
  
  <p>}</p>
  
  <p>I still receiving the same error. Also i changed the variable AllRoutes to true in config/cors.js file. My backbone file works(checked using console), however I cant fetch  data. Config/cors.js file is the following:</p>
  
  <pre><code>module.exports.cors = {
  
      // Allow CORS on all routes by default?  If not, you must enable CORS on a 
      // per-route basis by either adding a "cors" configuration object
      // to the route config, or setting "cors:true" in the route config to
      // use the default settings below.
      allRoutes: true,
  
      // Which domains which are allowed CORS access?
      // This can be a comma-delimited list of hosts (beginning with http:// or https://)
      // or "*" to allow all domains CORS access.
      origin: '*',
  
      // Allow cookies to be shared for CORS requests?
      credentials: true,
  
      // Which methods should be allowed for CORS requests?  This is only used
      // in response to preflight requests (see article linked above for more info)
      methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
  
      // Which headers should be allowed for CORS requests?  This is only used
      // in response to preflight requests.
      headers: 'content-type' 
      };
  </code></pre>
  
  <p>Am I missing something??  Ok I think I ve found something. Actually I am trying to direct to a home.ejs whrere I define a fetching.js (fetching data from data.php and definition of model-controller-views) where backbone code exists. Is it possible this file to work as it is, or I ve to define my MVC from sails??  Also I found that I am trying to get data from localhost:1337 (sails server). However I want to fetch data from apache localhost. How is it possible to request data to apache server while running sails?? In firebug I received the above:</p>
  
  <pre><code> GET http://localhost/sitec/fetchdata.php?widget=highlights 200 OK 47ms jquery.js (line 8706)
   GET http://localhost/sitec/fetchdata.php?widget=sentiment 200 OK 47ms jquery.js (line 8706)
   GET http://localhost/sitec/fetchdata.php?widget=tagsCloud 200 OK 47ms jquery.js (line 8706)
  </code></pre>
  
  <p>In response instead of having the object of json data (data.php returns json file), actually I can see the code of data.php file. Weird</p>