/    Sign up×
Community /Pin to ProfileBookmark

getHTTPObject();

Got this snippet of code, but getHTTPObject(); is not valid.
What .js library need to get this working?

<script src=”json2.js”></script>
var request;
function runAjax(JSONstring)
{
// function returns “AJAX” object, depending on web browser
// this is not native JS function!
request = getHTTPObject();
request.onreadystatechange = sendData;
request.open(“GET”, “parser.php?json=”+JSONstring, true);
request.send(null);
}

// function is executed when var request state changes
function sendData()
{
// if request object received response
if(request.readyState == 4)
{
// parser.php response
var JSONtext = request.responseText;
// convert received string to JavaScript object
var JSONobject = JSON.parse(JSONtext);

// notice how variables are used
var msg = “Number of errors: “+JSONobject.errorsNum+
“n- “+JSONobject.error[0]+
“n- “+JSONobject.error[1];

alert(msg);
}

}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@interfacetricksApr 16.2011 — Hi, Basically that function would just create a XMLHttpRequest object, presumably checking if it needs to use the older style (ie 5+6) ActiveX method instead. You can get good and brief explanation of it here.

http://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp

In short, your getHTTPObject() function would do something like this:

<i>
</i>function getHTTPObject()
{
if (window.XMLHttpRequest) return new XMLHttpRequest();
else return new ActiveXObject("Microsoft.XMLHTTP");
}


Note I haven't tested this so there may be a typo or something.
×

Success!

Help @CX_ASE spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...