在ror中的div中显示ajax响应 [英] display ajax response in div in ror
本文介绍了在ror中的div中显示ajax响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过ajax按下按钮后,使用下拉列表的值显示db中的数据. 这是我的Ajax代码:
I am trying to display data from db using the value of a dropdown after a button is pressed through ajax. This is my ajax code:
$(function () {
$("button").click(function(){
var value2 = $('select#dropdown option:selected').val();
$.ajax({
type: "GET",
dataType: "json",
url:"/mycontroller/action2",
data: {data1: value2 },
success:function(result1){
console.log(result1);
result1.forEach(function(){
$res_html = $("<div class= 'result1'>" + result1 + "</div>");
$('#test1').append($res_html);
$("#test1").text(result1);
})
}
})
});
});
我有一个div:
<div id= "test1"></div>
我的问题是我无法在ror视图的div标签中显示数据.
my problem is i am unable to display data in div tag of view in ror.
谢谢.
推荐答案
正确的语法应为:
$("#test1").html(result1);
这篇关于在ror中的div中显示ajax响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文