weixin_33744854 2015-03-02 10:37 采纳率: 0%
浏览 12

在ajax中显示值

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>
  • 写回答

2条回答 默认 最新

  • weixin_33724059 2015-03-02 10:40
    关注

    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.

    评论

报告相同问题?