如何解决为什么发表评论后我的页面无法重新加载视图?
在创建reddit克隆时学习ruby on rails,当我尝试发布评论时,我的控制台返回创建的评论,但它没有重新加载页面视图,并且返回错误提示
WebMvcLinkBuilder.methodOn(EmployeeController::class.java).one(id)
create.js.erb:
Uncaught TypeError: Cannot set property 'innerHTML' of null
at <anonymous>:3:52
at processResponse (rails-ujs.js:283)
at rails-ujs.js:196
at XMLHttpRequest.xhr.onreadystatechange (rails-ujs.js:264)
comments_controller:
document.getElementById("post-comments").innerHTML = "<%= escape_javascript(render partial: 'posts/comments',locals: {comments: @comments})%>"
For more details,here is the git repo
解决方法
您输入了一个选择器错误,因此像这样更改function pieChart() {
$.ajax({
url: 'http://localhost:3000/graph',type: 'post',dataType: 'json',crossDomain: true,success: function(jsonObj) {
var arr = [
['Road Type','Size']
];
$.each(jsonObj,function(i,tObj) {
console.log(tObj)
arr.push([String(tObj.title),parseFloat(tObj.data)]);
});
console.log(arr);
var data = google.visualization.arrayToDataTable(arr);
var options = {
title: '',is3D: true
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data,options);
}
});
}
,这应该起作用:
button.setOnClickListener {
//???
val rand = Random().nextInt()
phrase.text=rand.toString()}
这里的区别是comment/create.js.erb
而不是document.getElementById("post_comments").innerHTML = "<%= escape_javascript(render partial: 'posts/comments',locals: {comments: @comments})%>"
document.querySelector("#new_comment textarea").value = ""
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。