$(document).ready(function () {
debugger;
$.ajax({
type: "GET",
headers: {
"Accept" : "application/json",
"Content-Type": "application/json"
},
beforeSend: function (request) {
// request.setRequestHeader("X-DocuSign-Authentication"
// , "<DocuSignCredentials><Username>*******</Username><Password>****** </Password> <IntegratorKey>******</IntegratorKey></DocuSignCredentials>");
request.setRequestHeader("X-DocuSign-Authentication"
,"{\"Username\":\"********\",\"Password\":\"*****\",\"IntegratorKey\":\"*******\"}");
},
url: "https://demo.docusign.net/restapi/v2/login_information? api_password=false&include_account_id_guid=tr...
success: function (r) {
debugger;
},
error: function (xhr) {
alert(xhr.responseText);
}
});
});
我使用上面的登录,我得到响应代码200 ..但响应总是空白。即使我给错了密码,它仍然给200。 此外,在API部分激活部分为空白..请建议解决方案
答案 0 :(得分:6)
错误No 'Access-Control-Allow-Origin' header is present on the requested resource
表示通过jQuery / AJAX无法访问DocuSign。您将要通过其他语言执行登录请求并将变量传递给JS
以下是我在PHP上面提供的答案的更多细节。
这是一个简单的例子,我只是为了展示应该完成的过程,它必须进行修改以满足您的需求(特别是如果您不使用PHP)。
<div id='divBox'>Logging into DocuSign...</div>
<script src="js/jQuery2.1.1.js"></script>
<script>
$(function (){
$.ajax({
type: "GET",
url: "script.php",
dataType: "json",
success: function( data ){
if(!data.errorCode)
{
$('#divBox').html('Logged Into ' + data.name + ' (' + data.accountId + ') account!');
}else{
$('#divBox').html('Failed to Login!<br>Error: ' + data.errorCode);
}
},
error: function(){
alert("error");
}
});
});
</script>
<?
$email = "ENTER EMAIL HERE";
$password = "ENTER PASSWORD HERE";
$integratorKey = "ENTER INTEGRATOR KEY HERE";
$url = "https://demo.docusign.net/restapi/v2/login_information?include_account_id_guid=true";
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($status==200){
$response = json_decode($json_response, true);
print_r(json_encode($response['loginAccounts'][0]));
}else{
print_r($json_response);
}