简体   繁体   中英

Backbone.js Model urlRoot Error

location: htdocs -api.roamingcamper(RESTful + CodeIgnter) -backbone

Site = Backbone.Model.extend({
urlRoot: '/api.roamingcamper/index.php/api/site',
Defaults: .... }

SiteCollection = Backbone.Collection.extend({
model: Site,
url: 'http://localhost/api.roamingcamper/index.php/api/sites'
});

when i call the collection.create() and request a post method(via RESTful) it gives me a

POST http://localhost/api.roamingcamper/index.php/api/site  bad error

i have tried changing the urlRoot to

 urlRoot: '/api.roamingcamper/index.php/api/site

and

urlRoot: '/api.roamingcamper/index.php/api/site/

and it gives me a bad error

also tried

urlRoot: 'api.roamingcamper/index.php/api/site/'
urlRoot: 'api.roamingcamper/index.php/api/site

which gives a 404 error not found

but when i tried to test my api through REST Client it works fine

Please HELP me to figure this out

The RESTful didnt accept a JSON object, that's the reason why all my url post fail. So the best way should be pass a url encode data through ajax post

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM