I dont know how to show my values in ajax.Here my example
function check_valid() {
$.ajax({
url : '/something',
datatype : 'json',
async : false,
success : function(status) {
#status = ["1","abcdef"]
if (status[0] == 1) {
$("#check").css({
"display" : "block"
});
$("#com").html("Complete in #{status[1]}").css({
"display" : "block"
});
}
},
});
}
I want to show status[1]
in $("#com")
, but when I run app in sever it just show this:
Complete in #{status[1]}
I don't know how to show status[1]
in client. Please help me to fix that. I use ruby on rails. here my html:
<p id="com" style="display: none"></p>
You need to use string concatenation to append the value of the variable to the string. Try this:
$("#com").html('Complete in #' + status[1]).show();
I would also strongly suggest you remove async: false
from your AJAX settings as it is extremely bad practice.
Use this
function check_valid() {
$.ajax({
url : '/something',
datatype : 'json',
async : false,
success : function(status) {
#status = ["1","abcdef"]
if (status[0] == 1) {
$("#check").css({
"display" : "block"
});
$("#com").html("Complete in"+ status[1]).css({"display" : "block"}); //Youre concatination is wrong
}
},
});
}