Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8495885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:41:58+00:00 2026-06-10T23:41:58+00:00

I have created a Backbone.js model and want to save an instance to my

  • 0

I have created a Backbone.js model and want to save an instance to my MySql database.

var Website = Backbone.Model.extend({
    defaults: {   

                "title":"default title"
            },
    urlRoot : './websites'
});


var website = new Website();
website.save();​

I am using Slim.php to create a Restful API to my database. Here is the beginning of websites\index.php:

<?php

require 'Slim/Slim.php';

$app = new Slim();

$app->get('/websites', 'getWebsites');
$app->get('/websites/:id',  'getWebsite');
$app->post('/websites', 'addWebsite');
$app->put('/websites/:id', 'updateWebsite');
$app->delete('/websites/:id',   'deleteWebsite');

$app->run();

My save() triggers a POST which gets “moved permanently”:

Request
URL:localhost/SAMPLE-CODES/backbone.js-mysql-reading-json/websites
Request Method:POST Status Code:301 Moved Permanently

Then I see a second http request sent:

Request
URL:localhost/SAMPLE-CODES/backbone.js-mysql-reading-json/websites/
Request Method:GET Status Code:404 Not Found

My question is: why is this request not triggering the call to the ‘addWebsite’ function ?
I see that the second http request is a GET, when it should be a POST, but even then there is a route for that…

I have a folder /websites/

I also set the the .htaccess and http.conf as per the Slim routing documentation:

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

http.conf

<VirtualHost *:80>
    <Directory "c:/xampp/htdocs/SAMPLE-CODES/backbone.js-mysql-reading-json/websites/">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Edit:

The call to model.save() triggers an http POST to

localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites

.

This gets a ‘301 Moved Permanently’ with response header says:

localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites/

.

I assume this is due to the Slim recommended .htaccess settings.

Question: Is this OK to have this ‘301 Moved Permanently’, or do I already have an issue here?

Then I see 2nd http GET to

localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites/


Update:

I am still getting a 301 on

localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites

, then a GET to

localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites/

This second request works on a browser and returns

[{“id”:”1″,”title”:”titre site 1″},{“id”:”2″,”title”:”titre site 2″}]

So that would be the response for all records, but I wanted to save 1 record.
It seems the redirect 301 is wrong.

I have a feeling it is due to Slim not finding a matching route (Slim_Exception_RequestSlash would trigger a 301).

But why my Slim script not find the route?

The request for

localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites

is matched by:

$app->post(‘/websites’, function() {

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:42:00+00:00Added an answer on June 10, 2026 at 11:42 pm

    Problem solved thanks to orangewarp and this question:

    Why do I get a 301 redirect to folder name with slash?

    Solution was to add DirectorySlash Off in the .htaccess:

    My updated .htaccess (where the app calls Slim.php):

    RewriteEngine On
    DirectorySlash Off
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a model in backbone.js. var Content = Backbone.Model.extend({ // If you
I have this: var SomeNamespace = { Model: Backbone.Model.extend(), View: Backbone.View.extend({ model: new this.Model,
I have a View (created using Backbone.View.extend) and a JSON object, I actually get
With Backbone I have created a view for a model. I would like to
I have created a street view backbone view. The problem is that when shown,
Basically, I'm trying to do something like this: Person = Backbone.Model.extend({ validate: { ...
I have a view and collection like this: window.DmnView = Backbone.View.extend({ template: _.template($(#tmpl_dmnListItem).html()), events:
I am trying to get a CoffeeScript class to extend a Backbone.Model. I built
I have encountered a strange behaviour of the model validation in Backbone.js. When a
Newbie backbone question: Context: Building a shopping list with backbone I have a model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.