4

I am calling save() on a Backbone model. This works in every version of every browser I have tried except Safari and Safari on iOS.

In those 2 browsers the call fails before hitting the server with a 400 Bad Request error. The call looks like ../common/User/

My User model looks like this:

Backbone.Model.extend({

    idAttribute: "UserId",
    initialize: function() {
    }, 

    url: function () {
        var base = 'common/User/';
        return (this.isNew()) ? base : base + this.id;
    },...

The information I am trying to save looks like this:

{"BrowserType":"Safari","BrowserVersion":5.1,"ApplicationPath":"index"}

I not sure what other information I could provide to be helpful.

Any ideas why this could be happening?

EDIT The Request Header looks like:

Accept:application/json, text/javascript, */*; q=0.01
Content-Type:application/json
Origin:http://localhost:1087
Referer:http://localhost:1087/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
X-Requested-With:XMLHttpRequest
Mike Fielden
  • 10,055
  • 14
  • 59
  • 99

1 Answers1

2

Update the User model's url method to include a trailing slash:

url: function () {
    var base = 'common/User/';
    return (this.isNew()) ? base : base + this.id + "/";
},

I was having the same issues in my Backbone project -- all POST/PUT/PATCH requests for a particular model were failing in Safari and Mobile Safari although I had no problems in other browsers. As @mu is too short's comment suggests, adding a trailing slash to my model's url method fixed the issue.

Community
  • 1
  • 1
Hakan B.
  • 2,319
  • 23
  • 29