Object constructors

  • Thread starter frustratedcoder
  • Start date
F

frustratedcoder

How can I turn this:
Tmp = {
propertype : 'some prop'
};

into something that can be initialized as new Tmp(); ?
 
F

frustratedcoder

(own comment)

I'm trying to turn:
Ajax = {
Request : function(){
var req = Try.these(
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
) || false;

req.open('GET', 'includes/ajax-app.php', true);
req.onreadystatechange = function() {
if(req.readyState == 4)
if(req.status == 200)
alert(req.responseText);
};
req.send(null);
}
};
into an actual object that I can initialize like this:
var a = new Ajax.Request();

I want the Ajax.Request() to return actual responseText from the
request, but how do I get req.responseText out of the object?
 
R

RobG

frustratedcoder said:
(own comment)

I'm trying to turn:
Ajax = {
Request : function(){
var req = Try.these(
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
) || false;

req.open('GET', 'includes/ajax-app.php', true);
req.onreadystatechange = function() {
if(req.readyState == 4)
if(req.status == 200)
alert(req.responseText);
};
req.send(null);
}
};
into an actual object that I can initialize like this:
var a = new Ajax.Request();

The new operator must be used with a Function object, e.g.:

function AjaxObj(){...}
var a = new AjaxObj();

I want the Ajax.Request() to return actual responseText from the
request, but how do I get req.responseText out of the object?

Use your existing object and send the request synchronously so that
execution of the calling script is halted until the request returns.
Have a read of Jim Ley's page to get a better understanding:

<URL:http://jibbering.com/2002/4/httprequest.html>


maybe use the AjaxToolbox to save yourself a lot of work:

<URL:http://www.ajaxtoolbox.com>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top