# please note that I use ES6 syntax in JS.
# this: function() {...code here...}
# is the same as this: (()=> {...code here...});
# ES6 allows for shorthand annonymous functions
// wait for document to load
$(document).ready(()=> {
// declare variable
let foo = "hello world";
// fetch data from the back end
$.get("data.php?foo=" + encodeURIComponent(foo), (data)=> {
# the $.get is the exact same as the AJAX code you used above but shorthanded
// the 'data' is a parameter in the annonymous function that is storing the data from the back end
console.log(data); // test that we are getting the data properly
// remove table rows if they exist
$("#mytable tbody").remove();
$("#mytable").each(data, (i, item)=> {
// add your data to the table by appending to the table
# You would just continue this until you have all the cells you need filled. I'm going to skip to the end with adding the btn now
$("#mytable").append('<tbody><tr><td>'+item.booking_email+'</td><td>'+item.booking_number+'</td><td><button class="btn btn-lg btn-danger deletebtn" id="'+item.booking_number+'">Delete</button></td></tbody>');
/* the button has to have a unique ID to be called on so I assigned it the booking numbers to the ID.
Here's how we would call on it*/
$(".deletebtn").unbind().click((d)=> {
// you must unbind it first or you will have multiple events fire and you only want a single event to fire
// pass the annonymous function a parameter (can be anything really I use d for delete)
console.log(d.target.id); // check to make sure the button is getting an ID.
// post to back end to delete then when it succeeds, we delete that row.
$.post("data.php", {deletefoo: d.target.id}, (data)=> {
// delete row by calling on the target and removing the parent in this case being the row 'tr'
$(d.target).parents('tr').remove();
});
});
});
$("#mytable").show();
});
});
尝试在终端上运行mongo时出现错误。 我尝试重新安装并删除了锁定文件,然后重新启动了它,但仍然无法正常工作。我正在使用AWS,是否与AWS中网络设置的入站,出站有关,还是其他问题?
答案 0 :(得分:0)
就像上面的评论一样,如果您尝试使用127.0.0.1连接到同一主机上的mongodb实例,则这是mongodb配置问题,因此,不可能是任何AWS安全规则。
因此,考虑到这是mongodb问题,请首先尝试使用以下命令在主机内部修复它:
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
sudo service mongodb restart
sudo service mongod status
引用:https://stackoverflow.com/a/29083477/8407784
解决mongodb配置问题后,您需要测试来自另一台主机的连接,设置/etc/mongod.conf-bind_ip = 0.0.0.0(表示所有接口),仅用于测试
然后,您需要在主机实例上设置AWS安全规则,以允许外部实例在端口27017上访问它。