Search code examples
backbone.jsmobile-safari

backbone.js fetch failing in iOS safari, works in chrome


I've got a bit of a strange issue with iOS safari and backbone.js.

I am trying to fetch a collection via a post command, my backbone code is

 MyApp.search_results.fetch({data: data,type: 'POST', 
                         success: function(response){
                                 //I do a bunch of stuff with success
                          },
                         error: function(){
                           alert('problem getting search');
                          }
                });

when I run the above code in chrome (both desktop and in iPhone or Android) I get the result no problem.

But using safari on iOS, I get Failed to load resource: the server responded with a status of 404 (Not Found).

The big problem is my rails console does not even show that safari is sending the request, I see nothing past the previous request, so I'm getting a 404 error, but that actually isn't the problem.

Any ideas?

------------------------ update -----------------------

the problem is somehow caused by the type: 'POST'. I have removed and am now submitting a get request, but I would prefer this being a post type. So any suggestions on how to fix that would be great.


Solution

  • Backbone internally set's the request method to GET for the fetch function. Trying to override it can cause any number of inconsistencies and is not recommended.

    If you're trying to fetch data, then why not update your server code to read the GET params instead of POST params (or both)?