Created
May 18, 2012 05:45
-
-
Save torufurukawa/2723412 to your computer and use it in GitHub Desktop.
jQuery で Basic 認証のかかったリソースにアクセスする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>client</title> | |
<script type="text/javascript" src="jquery-1.7.2.js"></script> | |
<script type="text/javascript" src="jquery.base64.js"></script> | |
<script type="text/javascript"> | |
function getinfo() { | |
$.ajax({ | |
url: "http://example.com/", | |
success: function(data){alert('OK');}, | |
error: function(jqXHR, textStatus, errorThrown){ | |
alert(textStatus+": "+errorThrown); | |
}, | |
beforeSend: function(xhr) { | |
var credentials = $.base64.encode("username:password"); | |
xhr.setRequestHeader("Authorization", "Basic " + credentials); | |
}, | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="getinfo();">Press Me!</button> | |
<div id="result"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment