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 8855435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:08:03+00:00 2026-06-14T14:08:03+00:00

I have a model and I am trying to fetch it using model.fetch(); .

  • 0

I have a model and I am trying to fetch it using model.fetch();. The model’s urlRoot set to the back-end of my application (“/backend/item”), but right now I don’t have the back-end environment. So I decided to mock the results. I added a route inside my router:

"backend/item/:id": "data_getItem"

and a function:

data_getItem: function(id) {
  console.log("data_getItem: "+ id);
  return {
    animals: [
      {
        name: 'flying cat',
        type: 'none'
      }
    ]
  };
}

When running the application I can see ajax call to “http://127.0.0.1:8000/backend/item/1” but the console is empty and I get an error (the fetch function returns me to the error callback). Why is that? How can I mock the back-end?

EDIT
Actually @rjz helped me with the things I want to do, but I really want to know if an ajax call can be catched by backbone router.
My intuition tells me not because ajax call cannot execute backbone client code and therefore the router concept is not relevant. Am I right?..

  • 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-14T14:08:05+00:00Added an answer on June 14, 2026 at 2:08 pm

    I don’t think you want to use a Backbone.Router to catch your AJAX calls. If your goal is mocking out the backend of your project, you should use a testing framework to do this. A down and dirty way would be to use something like:

    • mock-ajax
    • jquery-mockajax

    or if you want to do something more like unit testing I would look at Jasmine and its AJAX mocking library.

    Update to answer your question:

    The short answer is no, a Backbone.Router cannot intercept AJAX calls.

    This is because the router works by listening to events that have to do with the URL. Specifically, the router is listening to the hashchange or popstate events (depending on if you are using pushState). Since AJAX calls do no interact with the URL they pretty much totally bypass this system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to model a network using C++. I have a struct called
I'm trying to get my models related using ReferenceProperty, but not have a huge
I have a Web Application that currently uses JQGrid but I'm trying to introduce
I have a model that I'm trying to retrieve an array of data from,
Let's say i have a Domain Model that im trying to make compatible with
Okay here is what I'm trying to do: I have a model object that
I am trying to build a registration form. I have a model for all
UPDATE: Redefined what I am trying to do. I have a model of Contact,
I have a coupon model and i am trying to calculate how much you
I have a posts model... I am trying to display this model on the

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.