Is it possible to pass credentials using AJAX to a webserver that request www-authentication?
I want to log in to a website that uses .NET Bsic www-authentication, and pass the credentials using ajax. When visiting the server with a browser, the browser prompts the user with an authentication/login window.
The html header contains this:
WWW-Authenticate: Basic
realm="hosting.xp"
MicrosoftSharePointTeamServices: 6.0.2.6568
X-Powered-By: ASP.NET
I want to access the site 'behind the scenes' by calling it from an ajax object, but I'm not sure how to handle the http header that requests the authentication.
I would like the ajax call to result in a specific user being logged in (the cookie set) so that the user can procedd to the site later and be 'already' logged in.
can this be done in the way I describe here?
Ajax stands for Asynchronous JavaScript and XML. In essence, Ajax is an efficient way for a web application to handle user interactions with a web page - a way that reduces the need to do a page refresh or full page reload for every user interaction.
AJAX is not a programming language. AJAX just uses a combination of: A browser built-in XMLHttpRequest object (to request data from a web server) JavaScript and HTML DOM (to display or use the data)
Ajax. Ajax is the traditional way to make an asynchronous HTTP request. Data can be sent using the HTTP POST method and received using the HTTP GET method. To make an HTTP call in Ajax, you need to initialize a new XMLHttpRequest() method, specify the URL endpoint and HTTP method (in this case GET).
You can pass the username and password in the URL like so:
http://username:[email protected]/secure
Here's an example with jQuery:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a.logMeIn').click(function(){
$.get('http://username:[email protected]/secure', null, function(response) {
alert(response);
});
});
});
</script>
<a href="#" class="logMeIn">Log me in!</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With