/    Sign up×
Community /Pin to ProfileBookmark

HTTP Request – Help

How can I submit a URL (used for validating through Active Directory) with HTTP Request and recieve the output from the URL and use that to pass or reject validation? The validation allready work, I just need to know how to send and get the url in javascript. without leaving the page.

IMPORTANT ** THIS IS RUNNING ON HTTPS

This is a sample URL:

[CODE]
https://some.domain/?api_method=user|exists&[email protected]
[/CODE]

Returns this value if true:

[CODE]
{“status”:”2″,”message”:”Email Address exists”}
[/CODE]

Else if user does not exist returns this value:

[CODE]
{“status”:”3″,”message”:”Username does not exist”}
[/CODE]

So I need to know if HTTP Request can pass a URL without leaving the page Im on, and then receive the value from the URL.
I am a little unsure of how to do this.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@cridleySep 05.2006 — [URL=http://www.w3schools.com/ajax/default.asp]http://www.w3schools.com/ajax/default.asp[/URL]
Copy linkTweet thisAlerts:
@Phill_PaffordauthorSep 05.2006 — Thanks for the link, but Im still having a hard time on understanding how to pass my URL and recieve back the validation (Sorry Newbie to JavaScript)
Copy linkTweet thisAlerts:
@cridleySep 05.2006 — My 60 second ajax lesson:

Ok, you're going to need a .js file linked to your page.

In it, you NEED:

[code=html]// Http request object
var xmlHttp

//Creates a new HTTP request object
function GetXmlHttpObject()
{
var objXMLHttp=null

if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}

return objXMLHttp
} [/code]


Now, in the same file the code triggered from whatever event you want, call :

[code=html]//call this to end a request to the server,
//pass in any parameters you need
function MyFunction(aParam)
{

//create http request object
xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}

//set a function which will be called when you get a
//response from the server
xmlHttp.onreadystatechange=stateChangeMyFunction

//the page you want to call (i have php as that's what i use
//but can be anything, html say)
var url="myurl.php"

//we want to send info as 'POST' (for 'GET' use 'GET')
xmlHttp.open("POST",url,true)
//The following line neede for post, not for get
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

// construct post string based on your parameters
var szPost = "myParam=" + aParam
// Send post request to server
xmlHttp.send(szPost)
}

//When server responds, the callback function gets called
//we set this up in the previous function.
//This is where you will process the output you requested from the server
function stateChangeMyFunction()
{
//if http request was succesful :
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
//Do whatever you want in here
//xmlHttp.responseText is the output from the requested file
alert(xmlHttp.responseText)
}
} [/code]
×

Success!

Help @Phill_Pafford 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.19,
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,
)...