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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:36:18+00:00 2026-05-14T22:36:18+00:00

UPDATE: Perhaps this wasn’t clear from my original post, but I’m mainly interested in

  • 0

UPDATE: Perhaps this wasn’t clear from my original post, but I’m mainly interested in knowing a best practice for how to structure javascript code while building a solution, not simply learning how to use APIs (though that is certainly important).

I need to add functionality to a web site and our team has decided to approach the solution using a web service that receives a call from a JSON-formatted AJAX request from within the web site. The web service has been created and works great. Now I have been tasked with writing the javascript/html side of the solution.

If I were solving this problem in C#, I would create separate classes for formatting the request, handling the AJAX request/response, parsing the response, and finally inserting the response somehow into the DOM. I would build properties and methods appropriately into each class, doing my best to separate functionality and structure where appropriate.

However, I have to solve this problem in javascript. Firstly, how could I approach my solution in javascript in the way I would approach it from C# as described above? Or more importantly, what’s a better way to approach structuring code in javascript?

Any advice or links to helpful material on the web would be greatly appreciated.

NOTE: Though perhaps not immediately relevant to this question, it may be worth noting that we will be using jQuery in our solution.

  • 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-14T22:36:19+00:00Added an answer on May 14, 2026 at 10:36 pm

    I was about to recommend JQuery – it’s fantastic for working with JSON/AJAX requests.

    It sounds like your primary concern is encapsulation; you’d like to separate your concerns. Javascript has a different feel from C# for creating OOP solutions, but you can still take advantage of many OOP features with Javascript. Here’s a good place to get started with Javascript’s OOP features:

    http://www.javascriptkit.com/javatutors/oopjs.shtml

    In the end, you can create a class that handles each of your requirements together (formatting, performing AJAX query, handling AJAX response):

    $.DataHandler = new function()
    {
        this.MyData = "Default Value",
        this.FormatData = function() { return this.MyData; }
        this.HandleResponse = function(data) { ... do something ... }
        this.DoAJAX = function()
        {            
            $.ajax({
                type: "GET",
                url: "/path/to/your/ajax",
                data: this.FormatData(),
                dataType: "json",
                success: this.HandleResponse
            });
        }
    } 
    

    I haven’t tested the above code, but you get the idea. Later, you can do something like this:

    $.DataHandler.MyData = "Some other data";
    $.DataHandler.DoAJAX();
    

    Anyhow, that’s the basic idea. There’s a lot of OOP/encapsulation you can do with Javascript, depending on your style and requirements.

    -Doug

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

Sidebar

Related Questions

This is a re-post of a topic on the Blackberry Development Forums, but I
This has been asked , but wasn't answered. The answer (use /warn:1 ) doesn't
Perhaps this is a bug, but it is weird it happens both in Safari
Perhaps this is normal, but in my Oracle 11g database I am seeing programmers
Can you create websites with Chinese characters in PHP? UPDATE: Perhaps I should have
Update Sir this is current code of my web page.I made changes according to
Update Mr Wizard's answer gives pixel-perfect results, but it is Windows-only and destroys the
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Apologies - am not good at SQL. Perhaps this is a simple query -
Update: I deleted my motivation because it seems to distract readers. This is not

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.