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

  • SEARCH
  • Home
  • 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 9132959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:24:12+00:00 2026-06-17T08:24:12+00:00

So I have been working with basic Backbone.js to create a simple demo page

  • 0

So I have been working with basic Backbone.js to create a simple demo page that is a basic User Manager. I run the same function whether I am creating (POST) or updating (PUT) a user’s information. Both the POST and PUT requests are successful (I.E. calling my “success” function) however only the PUT command will trigger the router, the POST request does not trigger the same line of code while it DOES trigger the success function.

Below is my events code. The saveUser function takes care of both the PUT and POST requests but the router in success is only fired from a successful PUT request, not from a successful POST request (even though both are successful in updating the database).

events: {
            'submit .edit-user-form': 'saveUser',
            'click .delete': 'deleteUser'
        },
        saveUser: function (ev) {
            var userDetails = $(ev.currentTarget).serializeObject();
            var user = new User();
            reply = user.save(userDetails, {
                success: function (){
                    router.navigate('', {trigger: true});
                },
                error: function(){
                    $("#editError").toggle();
                    $("#editError").html("Error:<br/>"+reply.status+" : "+reply.statusText+"<hr/>");
                }
            });
            return false;
        },
        deleteUser: function (ev){
            $.ajaxSetup({
                headers: {
                    'method':"DeleteUser"
                }
            });
            reply = this.user.destroy({
                success: function (){
                    router.navigate('', {trigger: true});
                },
                error: function(){
                    $("#editError").toggle();
                    $("#editError").html("Error:<br/>"+reply.status+" : "+reply.statusText+"<hr/>");
                }
            })
            return false;
        }

Here is the router code:

    var Router = Backbone.Router.extend({
        routes:{
            'new': 'editUser',
            'edit/:id': 'editUser',
            '': 'home'
        }
    });
    var router = new Router();
    //ROUTES
    router.on('route:home', function(){
        alert("1");
        userList.render(),
        editUser.render({});
    });
    router.on('route:editUser', function(id){
        userList.render();
        editUser.render({id: id});
    });
    //NECESSARY
    Backbone.history.start();`

Any help would be appreciated!

Thanks!

  • 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-17T08:24:12+00:00Added an answer on June 17, 2026 at 8:24 am

    The problem is that when you’re creating a new user, you’re already at the url "", and router.navigate(newUrl) only triggers if newUrl is different than the current page url.

    See https://github.com/documentcloud/backbone/issues/652.

    To fix, change

    router.navigate('', {trigger: true});
    

    To

    Backbone.history.fragment = null; // Forces the current URL to be dirty
    router.navigate('', {trigger: true}); // Now, Backbone thinks the new URL is different
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with NSArray s and NSMutableArray s that store NSDate objects
I have been working on an iPhone app that has a feature of uploading
I have been working on getting a basic ATL project to compile in Visual
I have been working on a website that has to do with a subscription
I have been working on a basic tile engine for a project of mine
I'm currently learning PHP and MySQL and I have been working from a basic
I have been working on a basic site for my family's recycling yard store.
I have an app that I have been working on and I did a
I have been working with some basic sql databases and am designing an application
I have been working on android from 6 months. So I have basic idea

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.