【发布时间】:2017-09-22 00:23:57
【问题描述】:
我有一个 javascript 函数,如下所示,我将它托管在 S3 上
function myFunction() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
document.getElementById("testing").innerHTML = this.responseText;
}
};
xhttp.open("GET","https://id.execute-api.ap-southeast-1.amazonaws.com/prod/lambdafunction", true);
xhttp.send();
}
这个lambdafunction写在Node.js如下
'use strict';
console.log('Loading function');
exports.handler = (event, context, callback) => {
let response = {
statusCode: '200',
body: JSON.stringify({ error: 'you messed up!' }),
headers: {
'Content-Type': 'application/json',
}
};
context.succeed(response);
//callback(null, context); // Echo back the first key value
//callback('Something went wrong');
};
我期望的是带有 id 测试的 div 将被 error: 'you messed up! 取代,但什么也没发生?我可以知道哪个部分出了问题吗?
【问题讨论】:
标签: node.js amazon-web-services aws-lambda aws-api-gateway