title: PHP Cross Domain (AJAX) Proxy with Backbone
body: <p>Here is the problem I am facing.</p>
  
  <p>I am building my rest api with Laravel 4 on domain A.</p>
  
  <p>The api will supply JSON's to my app which is on domain B.</p>
  
  <p>To avoid cross origin policy problems I have done two things:</p>
  
  <ol>
  <li>Client side - I have downloaded a PHP proxy script - on domain B - and use it to send GET, POST requests to my api on domain A.</li>
  </ol>
  
  <p>I've used the script located here, on <a href="https://github.com/softius/php-cross-domain-proxy" rel="nofollow">github</a>.</p>
  
  <ol>
  <li>Serve side, I have enabled Laravel to accept CORS.</li>
  </ol>
  
  <p>All is well, things are "sort-of" working.</p>
  
  <p>The front end is controlled by Backbone, which leads me to the source of my problem.</p>
  
  <p>Looking at the proxy's docs, here is how it should be used with jQuery:</p>
  
  <pre><code>$('#target').load('http://www.yourdomain.com/proxy.php', {
      csurl: 'http://www.cross-domain.com/',
      param1: value1,
      param2: value2
  });
  </code></pre>
  
  <p>Basically, I send a <strong>csurl</strong> with the value of my REST Api domain - domainA</p>
  
  <p>The other params (param1 and param2) are used to send different things to the api, <strong>like the csrf token and so on</strong>.</p>
  
  <p>Getting over to Backbone, I can't seem to make the Backbone model work properly and I'm not sure how to handle sending the params.</p>
  
  <p>Here is the backbone model:</p>
  
  <pre><code>var MyModel = Backbone.Model.extend({
      url: 'http://domainB.dev/proxy.php'
  });
  </code></pre>
  
  <p>In my view, I instantiate it and try to pass the parameters:</p>
  
  <pre><code>var myModel = new MyModel();
  myModel.save({
      data: {
          csurl: 'http://domainA.dev'
          param1: 'mytoken'
      }
  }, {
      success: function() {},
      error: function() {}
  });
  </code></pre>
  
  <p>The data does not reach my api - I find it in the post, the post actually works - but I don't get a success callback.</p>
  
  <p><strong>Basically, I don't know how to implement the proxy's docs into a Backbone.</strong></p>
  
  <p>Any ideas?</p>