Object-Oriented AJAX with JavaScript | CodeGuru

Object-Oriented AJAX with JavaScript

Introduction My goal was to create a friendly, easy to use, and maintainable object-oriented AJAX class. In creating this, I have solved most of the issues with ASYNC and SYNC callbacks with multiple requests. Also, I have made it easy to post data without having to worry about building a post back string. The code […]

Written By
CodeGuru Staff
CodeGuru Staff
Sep 27, 2007
3 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Introduction

My goal was to create a friendly, easy to use, and maintainable object-oriented AJAX class. In creating this, I have solved most of the issues with ASYNC and SYNC callbacks with multiple requests. Also, I have made it easy to post data without having to worry about building a post back string. The code also uses some creative techniques to create object-oriented style classes and objects like that found in C# style classes, so the look and feel will be closely related. Because the code is tightly knit, the size of the .js file is an amazing 4.2 Kb. But, don’t let the size fool you; sometimes little things pack a big punch. Well, enough said; jump into the API and see how this bad boy works.

Classes

Title: Connection
Namespace: System.Net.Ajax
Description: The main AJAX connection class for connecting to a webpage or xml resource.
Constructor(s) Description Return Value
Connection() Empty Constructor Connection Object
Connection(PageRequests) Constructor filled with System.Net.Ajax.PageRequests class object. Connection Object
Method(s) Description Return Value
GetType() Gets the type of class object. Class Object Name
Init() Internal method for constructor initialization. Constructed Object
Create() Internal method for creating the ActiveX Ajax or XMLHttpRequest object. New Ajax Object
Open() Opens the connection and retrieves the webpage or xml resource. Info Object
Properties Description Return Value
ActiveXObject Gets the current running ActiveX Ajax or XMLHttpRequest object. Ajax Object
PageRequests The PageRequests class containing all the Request Objects. PageRequests Object
Current The currently working request object. Current Request Object
Title: PageRequests
Namespace: System.Net.Ajax
Description: The PageRequests class for holding an array collection of Request class objects.
Constructor(s) Description Return Value
PageRequests() Empty Constructor PageRequests Object
PageRequests(Request) Constructor filled with System.Net.Ajax.Request PageRequests Object
Method(s) Description Return Value
GetType() Gets the type of class object. Class Object Name
Init() Internal method for constructor initialization. Constructed Object
AddRequest(Request) Adds a Request object to the array collection. Nothing
Properties Description Return Value
Requests The array collection of request objects. Array of Request
Title: Request
Namespace: System.Net.Ajax
Description: The Request class for holding all the properties and parameters for the request.
Constructor(s) Description Return Value
Request() Empty Constructor Request Object
Request(RequestMethod) Constructor filled with System.Net.Ajax.RequestMethod. Request Object
Request(RequestMethod, URL) Constructor filled with System.Net.Ajax.RequestMethod and URL. Request Object
Request(RequestMethod, URL, Callback) Constructor filled with System.Net.Ajax.RequestMethod and URL and Callback Method. Request Object
Request(RequestMethod, URL, Callback, Async) Constructor filled with System.Net.Ajax.RequestMethod and URL and Callback Method. Request Object
Request(RequestMethod, URL, Callback, Async, UserObject) Constructor filled with System.Net.Ajax.RequestMethod and URL and Callback Method and Async setting and optional UserObject. Request Object
Method(s) Description Return Value
GetType() Gets the type of class object. Class Object Name
Init() Internal method for constructor initialization. Constructed Object
AddParam(Parameter) Adds a Parameter object to the request object parameter array collection. Nothing
AddParam(Name, Value) Adds a name with value to the request object parameter array collection. Nothing
Properties Description Return Value
Method The HTTP request method GET or POST. string
URL The URL to retrieve. string
Params The parameters to send with the POST. Parameter Object Array
Callback The method to callback when the request is loading and complete. Method Reference
Async Whether the call should be async or sync. Bool
UserObject An extra free object to send back with the callback method. Any Type
Title: Parameter
Namespace: System.Net.Ajax
Description: The Parameter class for holding a name and value of a post parameter.
Constructor(s) Description Return Value
Parameter() Empty Constructor Parameter Object
Parameter(Name, Value) Constructor filled with a Name and Value. Parameter Object
Method(s) Description Return Value
GetType() Gets the type of class object. Class Object Name
Init() Internal method for constructor initialization. Constructed Object
Properties Description Return Value
Name The parameter name to post. string
Value The parameter value to post. string
Title: Namespace
Namespace: Window.Namespace, Namespace
Description: A custom object for handling the creation of namespaces in javascript.
Method(s) Description Return Value
Register(Name) Registers a namespace for use in javascript. Nothing
Title: RequestMethod
Namespace: System.Net.Ajax
Description: An enumeration for handling the HTTP Method.
Properties Description Return Value
Get For sending a Get HTTP Request. string
Post For sending a Post HTTP Request. string
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.