【发布时间】:2017-04-12 15:58:11
【问题描述】:
我是一个样板程序员,所以对脚本如何深入工作的技术不是很熟练。
我有一个用于从 Yammer 中提取用户信息的 yammer api:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<span id="yammer-login"></span>
<script type="text/javascript" data-app-id="bdlZbJHCm1RY8pMUbuoBlQ" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
<script>
yam.getLoginStatus(
function (response) {
var result = 1625803434;
if (response.authResponse) {
console.log("logged in");
yam.platform.request({
url: "users/"+result+".json",
method: "GET",
data: { //use the data object literal to specify parameters, as documented in the REST API section of this developer site
"User_Id": result,
},
success: function (user) { //print message response information to the console
str = JSON.stringify(user, null, 4); // (Optional) beautiful indented output.
document.write(str);
},
error: function (user) {
alert("There was an error with the request.");
}
});
}
else {
alert("not logged in")
}
}
);
</script>
</body>
</html>
我必须使用结果变量将 Yammer id 硬编码到其中。
我尝试添加一个输入框,然后 yam.getLoginStatus 失败: alert("请求出错。");
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form id="frm1" action="#" method="post">
Yammer ID: <input type="text" name="y_id"><br><br>
<input type="submit" onclick="yam_id()" value="Submit">
</form>
<span id="yammer-login"></span>
<script type="text/javascript" data-app-id="bdlZbJHCm1RY8pMUbuoBlQ" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
<script>
yam.getLoginStatus(
function (response) {
var result = 1625803434;
frm_i=document.getElementById("frm1");
result=frm_i.elements[0].value;
// alert (result);
if (response.authResponse) {
console.log("logged in");
yam.platform.request({
url: "users/"+result+".json",
method: "GET",
data: { //use the data object literal to specify parameters, as documented in the REST API section of this developer site
"User_Id": result,
},
success: function (user) { //print message response information to the console
str = JSON.stringify(user, null, 4); // (Optional) beautiful indented output.
document.write(str);
//console.dir(user);
},
error: function (user) {
alert("There was an error with the request.");
}
});
}
else {
alert("not logged in")
}
}
);
</script>
有谁知道如何简单地为这个脚本添加一个输入框?
【问题讨论】:
标签: javascript user-input yammer