Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone.js issuing GET requests for `model.save()` calls
    text
    copied!<p>I have a Backbone application in which I am creating a new model and saving it. Here's a snippet of the code, with debugging, in CoffeeScript:</p> <pre><code>newListing = new Listing console.log "New?", newListing.isNew() newListing.save creation, { wait: true success: (model, response) =&gt; console.log "SAVED", model console.log "RESPONSE", response } </code></pre> <p>For debugging, I have also overridden <code>Backbone.sync</code>:</p> <pre><code>oldSync = Backbone.sync Backbone.sync = (method, model) -&gt; console.log "Syncing:", method, model oldSync(arguments...) </code></pre> <p>Usually, this works fine. I get this in the console:</p> <pre><code>New? true Syncing: create &gt; Listing SAVED &gt; Listing RESPONSE &gt; Object </code></pre> <p>And in the Network Inspector I see:</p> <pre><code>listings POST 200 application/json </code></pre> <p>I also see a POST request logged in my (Rails) application log.</p> <p>However, after creating a few Listings, I start to see the following behavior on the console:</p> <pre><code>New? true Syncing: create &gt; Listing SAVED &gt; Listing RESPONSE [&gt; Object, &gt; Object, &gt; Object, &gt; Object, &gt; Object, &gt; Object] </code></pre> <p>where each <code>Object</code> is a Listing already saved in the database. The Network Inspector and my application log also indicate that Backbone performed a GET request to /listings. Furthermore, the <code>Listing</code> in the third line that has been "SAVED" is a client-side representation of the listing (without some additional details that the server usually inserts).</p> <p>I have not been able to find any pattern to this behavior; sometimes, Backbone insists on sending GET after GET, and after a refresh it starts working. Sometimes it acts up until I restart my application server. Happy to explore any suggestions!</p> <p>[Edit]</p> <p>Alright, after some sleuthing, it appears that after I call <code>fetch()</code> on a <code>Listings</code> collection, <code>Listing#save()</code> starts doing this. The issue only appears on my laptop, which is running Chrome Dev (v19). On other browsers and older versions of Chrome it works fine.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload