Ajax 请求
$.ajax({
type: "GET",
url: "http://localhost/CI2/index.php/login/testfunc",
data: {macro: selectedmacro},
async: false,
success: function (data) {
$('#tinyeditor').val(data);
$('#p2').html(data);
}
});
PHP
echo "This is a test";
HTML
<p id = 'p2'>fer</p>
<input type = "text" id = "tinyeditor" />
什么有效:
$('#p2').html(data);
有效,并将“fer”替换为“这是一个测试”
$('#tinyeditor').val('data');
也可以将“data”字符串插入输入字段
问题
$('#tinyeditor').val(data);
无法将“This is a test”插入输入字段。该字段保持空白。
最佳答案
首先使用JSON.parse(data)
解析数据并尝试插入。
关于jquery - 无法将ajax返回的数据插入输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29787577/