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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:56:56+00:00 2026-05-29T08:56:56+00:00

With the below javascript code i am trying some BackboneJs concepts. Couldn’t figure out

  • 0

With the below javascript code i am trying some BackboneJs concepts. Couldn’t figure out why the response after invoking a XHR request is HTML of full page rather than the serialized version of Person class. Have a look below
Server Side Code is of C# and ASP.NET 2.0

note: forget the urland urlroot on the model, i am using the backbonejs Sync

Javascript

window.Person = Backbone.Model.extend({
    defaults: {
        id: Math.random(),
        name: "Type your name"
    },
    initialize: function (model) {
        this.bind("change", this.ModelChanged);
    },
    ModelChanged: function () {

    },
    url: "CreatePerson",
    urlRoot: "/index.aspx/"
});

Backbone.sync = function (met, mod, op) {
    switch (met) {
        case "create":
            break;
        case "update":
            break;
        case "delete":
            break;
        case "read":
            break;
        default:
            break;

    }
};

Server side code

    [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static Person CreatePerson(Person newPerson)
    {
        List<Person> peopleList = HttpContext.Current.Session["People"] as List<Person>;
        if (peopleList == null)
        {
            peopleList = new List<Person>();
        }
        Person p1 = new Person();
        p1 = newPerson;
        peopleList.Add(p1);
        HttpContext.Current.Session["People"] = peopleList;
        return p1;
    }

Person class

public class Person
{

    public string Id
    {
        get;
        set;
    }

    public string Name
    {
        get;
        set;
    }


}

Finally the test code

var x = new Person({
    name: "StackOverflow"
});
$.post("index.aspx/CreatePerson", "{" + JSON.stringify(x) + "}", function () {
    console.log(arguments)
});
  • 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-29T08:56:57+00:00Added an answer on May 29, 2026 at 8:56 am

    I don’t understand why but jQuery made me follow this weird procedure to get this done.

    It serializes valid json to URL encoded format & not json string which is wrong.

    $.ajaxSetup({
        contentType: "application/json; charset=utf-8"
    });
    
    Backbone.sync = function (met, mod, op) {
        console.log("method", met, "model", mod);
        switch (met) {
            case "create":
                $.post("index.aspx/CreatePerson", { "newPerson": mod.attributes }, function () { console.log(arguments) }, "json");
                break;
            case "update":
                var x = { "newPerson": mod.attributes };                
                x = JSON.stringify(x);                
                $.post("index.aspx/CreatePerson", x, function () { console.log(arguments) });
                break;
            case "delete":
                break;
            case "read":
                break;
            default:
                break;
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to execute the below code in my javascript and got some
I'm trying to debug some javascript I wrote and can't figure out why it's
I am trying to work out some performance problems with some JavaScript I've been
I'm trying to increment through JQuery loop to fill out some HTML code with
The below code is in my javascript/jquery script, but for some reason Firebug tells
I'm currently trying to learn OO Javascript so I can write some cleaner code.
I'm trying to figure out a good method for loading records sequentially using some
After trying to append some code to a div layer I received the following
HI all, Below mentioned javascript code works fine in all browsers including chrome(from second
Consider the JavaScript code below, inspired from the YUI documentation on YAHOO.lang.extend . In

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.