通过Ajax调用加载文本到文本区域文本、加载、区域、Ajax

2023-09-10 21:17:03 作者:? 深情不及久伴 *

我想加载从数据库中检索到一个textarea的一些文字。用户点击一个链接:

I would like to load some text retrieved from a dB into a textarea. The user clicks a link:

<a class="editlink" id="<?php echo $review['id']; ?>" href="#"><?php echo $review['title']; ?></a>

JQuery的传递ID来GO.PHP:

JQuery passes the ID to GO.PHP:

$(".editlink").click(function() {
    $.get("go.php", {param: $(this).attr('id')}, 
        function(data) {
            $('textarea#area1').html(data);
        });    
    return false;
});

GO.PHP检索来自分贝的文字:

GO.PHP retrieves the text from the dB:

$qry = mysql_query("SELECT * FROM reviews WHERE id = ".$_GET['param']." "); 
while($review = mysql_fetch_array($qry)) {
    echo $review['description'];
} 

证实了萤火虫consolle,标识和文字都是正确检索。在万阿英,蒋达清是,我不能够将文本到textarea的:

As confirmed by Firebug consolle, ID and the text are retrieved correctly. The probelm is that I'm not able to place the text into the textarea:

<textarea id="area1" rows="30" cols="55"></textarea>

我想:html的(数据)的.text(数据),.VAL(数据),但没有显示任何内容。 (请注意,在分贝文本可能包含HTML标签,我想保留)。

I tried: .html(data), .text(data), .val(data) but none display anything. (Please note that the text in the dB may contain HTML tags that I would like to keep).

推荐答案

您需要设置文本区域的价值。

You need to set the text areas value.

$("#textareaID").val("value of text area");

我把这个成头部引用查询一个空白的HTML文档,它能正常工作。

I put this into a blank HTML doc referenced query in the head and it worked fine.

<form>
  <textarea id="test"></textarea>
</form>
<script>
    $('#test').val('testing');
</script>
 
精彩推荐
图片推荐