问题描述
谁能分享如何通过浏览器而不是通过 Postman 或 curl 运行和测试 AWS API Gateway 和 Lambda。 我正在尝试使用 HTML + JavaScript(使用对 API 的 ajax 调用)创建一个简单的演示应用程序,并调用 AWS API。 我确实尝试过邮递员和 curl 都工作正常,但是从浏览器(ajax 调用)调用时它失败了。
任何指针都会很棒。
代码片段:
$.ajax({
type: "POST",url : URL,dataType: "json",mode: 'no-cors',crossDomain: "true",contentType: "application/json; charset=utf-8",data: JSON.stringify(data),success: function () {
// clear form and show a success message
alert("Your entry is saved Successfuly");
document.getElementById("my-form").requestFullscreen();
location.reload();
},error: function() {
// show an error message
alert("Seems some issue with the entry,try again.")
}
});
到目前为止,这是一个简单的演示,用于获取用户名和其他详细信息,并通过 AWS Lambda (Python) 将其保存到 DynamoDB。 正在调用 AWS Lambda 函数,但在响应中失败。
示例代码是 https://codepen.io/mayanktripathi4u/pen/QWdrPOG 使用 JS Fetch 尝试了各种选项;阿贾克斯; XMLHttpResponse 等。无效。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)