Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2011, 05:18 PM   PM User | #1
dev.genius
New to the CF scene

 
Join Date: Feb 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
dev.genius is an unknown quantity at this point
Unhappy Help with testing

I'm working on a framework, and one of its most important parts is its Ajax module. Unfortunately, I am horrible with Ajax. I was just wondering if someone could help me with testing this.

Here is the code:

Code:
/* $.load(w, x, y, z) -- returns the requested file.

PARAMETERS
-----------------------------
w - url of file to load
x - the callback function. Will be passed the reponse text as a parameter
y - Boolean value representing whether the connection should be synchronous
z - an optional function that will be called if an error occurs. Will be passed the response text as a parameter
*/
var $ = {};
$.load = function(w, x, y, z) {
    var httpRequest = function() {
	    if(window.XMLHttpRequest) {
	        return new XMLHttpRequest();
		} else if(window.ActiveXObject) {
		    var t = ["MSXML2.XmlHttp.6.0", "MSXML2.XmlHttp.3.0"];
			for (var i = 0; i < 2; i++) {
			    try {
				    var n = new ActiveXObject(t[i]);
					return n;
				} catch(e) {}
			}
		}
		return null;
	};
	httpRequest.open("GET", w, y);
	if(y) {
	    var a1 = httpRequest;
		var a2 = x;
		if(z) {
		    var a3 = z;
		} else {
		    var a3 = false;
		}
		function f() {
		    if(a1.readyState == 4) {
			    if(a1.status == 200) {
				    a2(a1.responseText);
				} else {
				    if(a3 != false) {
					    a3(a1.responseText);
					}
				}
			}
		}
		httpRequest.onreadystatechange = f;
	}
	httpRequest.send(null);
	if(!y) {
	    x(httpRequest.responseText);
	}
	return httpRequest;
};
dev.genius is offline   Reply With Quote
Old 02-06-2011, 06:00 PM   PM User | #2
dev.genius
New to the CF scene

 
Join Date: Feb 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
dev.genius is an unknown quantity at this point
Oh, and I forgot to mention: I keep getting an error and I don't know why.
Error Message:
Code:
Expected (
dev.genius is offline   Reply With Quote
Old 02-06-2011, 06:01 PM   PM User | #3
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
If you're writing your own framework, whose most important part is its AJAX module, isn't it sort of a prerequisite for you to *not* be horrible with AJAX?
venegal is offline   Reply With Quote
Users who have thanked venegal for this post:
dev.genius (02-06-2011)
Old 02-06-2011, 06:09 PM   PM User | #4
dev.genius
New to the CF scene

 
Join Date: Feb 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
dev.genius is an unknown quantity at this point
Good point.
dev.genius is offline   Reply With Quote
Old 02-06-2011, 06:09 PM   PM User | #5
dev.genius
New to the CF scene

 
Join Date: Feb 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
dev.genius is an unknown quantity at this point
Never mind with this post. I figured out what I was doing wrong.
dev.genius is offline   Reply With Quote
Old 02-07-2011, 10:25 AM   PM User | #6
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
I'd have thought a prerequisite for writing a JS framework, especially one that deals with AJAX, is thinking to yourself, "Hold on, there's chuffing hundreds of these things knocking about, almost all of which are going to be better written, better documented and better maintained than mine. I may as well save myself the bother and go and have a nice cup of tea and a sit down."
Spudhead is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:56 PM.


Advertisement
Log in to turn off these ads.