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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:41:22+00:00 2026-06-01T05:41:22+00:00

Note: I know this is wrong , but this is a technical requirement by

  • 0

Note: I know this is wrong, but this is a technical requirement by the server team.

I have a User object that extends Backbone.Model. It receives it’s data using normal, mostly good, JSON from the server.

HOWEVER there is a requirement when saving THE SAME INFORMATION to encode emails with url encoding.

When receiving the data it is possible to pre-process it with the Backbone.Model.parse method, is there an equivalent way to pre-process the data before sending it? (without overriding the sync method)

  • 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-01T05:41:24+00:00Added an answer on June 1, 2026 at 5:41 am

    I overrode Backbone.sync to change the format of the data to form encoded. However, with this method saving attributes that are arrays becomes a problem.

    There’s probably a better way to override sync, but I added this code to around line 1180 of the backbone.js file.

    //convert to form encoded
    if (Backbone.sendFormEncoded) {
      if (type === 'PUT' || type === 'DELETE' || type === 'POST') {
        params.contentType = 'application/x-www-form-urlencoded';
        var kvps = [], regEx = /%20/g;      
        var obj = model.toJSON();
        for (var key in obj) {
          if (obj.hasOwnProperty(key)) {
            if(obj[key]) {
              kvps.push(encodeURIComponent(key).replace(regEx, "+") + "=" + encodeURIComponent(obj[key].toString()).replace(regEx, "+"));
            } else {
              kvps.push(encodeURIComponent(key).replace(regEx, "+") + "=" + encodeURIComponent(obj[key]));
            }
          }
        }
        params.data = kvps ? kvps.join('&') : {};
      }
    }
    

    Be sure to set Backbone.sendFormEncoded to true for this block of code to run.

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

Sidebar

Related Questions

NOTE: I know there are many questions that talked about that but I'm still
Note: this is NOT about concurrency. This is about the thread macro. I know
Before I ask this, do note: I want this for debugging purposes. I know
Not sure what I'm doing wrong but I have two services one is WCF
I know this is simple but I can't figure it out today and I
Note: I've cross-posted this question in the grails-user mailing list This weekend using this
I'm most likely going about this the wrong way, but I was wondering if
I know this is a srs beginner question, but here goes: I am trying
I'll like to know if this is a bug or wrong implementation ..... am
Note: I am not sure if this is better here, or at superuser, but

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.