这篇文章解释了如何通过javascript登录SugarCRM实例。让我们以通过JavaScript的REST API为例。创建一个包含javascript的html文件,我们将需要jquery。在HTML文件<ANYNAME> .html中提供正确的Javascript路径 。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SugaRCRM REST API Example through Javascript</title>
<script src='jquery.js'></script>
<script src='rest.js'></script>
</head>
</script>
</head>
<body >
<div class="hd">SugaRCRM REST API Example through Javascript</div>
</body>
</html>
现在创建一个rest.js
var api_url = "<SUGAR_URL>/service/v2/rest.php";
var user_name = '<USERNAME>'; //SugarCRM username
var password = '<PASSWORD>'; //SugarCRM password
var params = {
user_auth:{
user_name:user_name,
password:password,
encryption:'PLAIN'
},
application: 'SugarCRM RestAPI Example'
};
var json = JSON.stringify(params);
$.ajax({
url: api_url,
type: "POST",
data: { method: "login", input_type: "JSON", response_type: "JSON", rest_data: json },
dataType: "json",
success: function(result) {
if(result.id) {
//HERE: you will have out put from rest
alert("sucessfully LOGIN Your session ID is : " + result.id);
}
else
alert("Error");
},
error: function(result) {
alert("Error");
}
});
成功后,您将获得登录方法(成功或失败)的响应。