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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:20:30+00:00 2026-05-27T18:20:30+00:00

This is my front-end code (using fetch ) var MyModel = Backbone.Model.extend(); var MyCollection

  • 0

This is my front-end code (using fetch)

    var MyModel = Backbone.Model.extend();
    var MyCollection = Backbone.Collection.extend({
        url: '/questions',
        model: MyModel
    });
    var coll = new MyCollection();
    coll.fetch({
        error: function (collection, response) {
            console.log('error', response);
        },
        success: function (collection, response) {
            console.log('success', response);
        }
    });

and this is my back-end code (using app.get)

app.get('/questions', function (request, response) {
    console.log('Inside /questions');
    response.writeHead(200, {
        'Content-Type': 'text/json'
    });
    response.write('{test:1}');
    response.end();
});

The problem is that although the response is as expected, the client-side error callback is called. When I remove the line response.write('{test:1}');, the success callback is called. Any ideas as to what I might be doing wrong?

  • 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-05-27T18:20:31+00:00Added an answer on May 27, 2026 at 6:20 pm

    Well {test:1} is not valid JSON.

    { "test":"1" }
    OR
    { "test":1 }
    is however, try one of those instead.

    Keys are strings in JSON, and strings in JSON must be wrapped in double quotes check out JSON.org for more information.

    To ensure you have valid JSON for more complex objects just use JSON.stringify():

    var obj = { test : 1 };
    response.write(JSON.stringify(obj)); //returns "{"test":1}"
    

    Also, the correct Content-Type for json is application/json

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

Sidebar

Related Questions

I've never come across this extension before. It's being used for a front-end interface
I have my front end script which has the following jQuery code: $.get(/backend/post.php, {
I have a front-end Access 2007 database connecting to MySql tables using MySQL ODBC
I'm using this code to update an object (MySQL) that we have received via
I'm using safecracker in expressionengine to display a form to front end users. User
So far, I've had great success using PyAMF to communicate between my Flex front-end
I'm building a front-end content editing module for my own framework using a WYSIWYG
I'm writing a graphical application using Objective-C for the front end and C++ for
On the front-end, I've initialised FB and login using: window.fbAsyncInit = function () {
I am working on the front end of a jsp based app. We're using

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.