使用jquery函数处理ajax调用?

使用jquery函数处理ajax调用?,jquery,ajax,redactor,Jquery,Ajax,Redactor,下面的文本区域是通过ajax调用生成的。但是编辑程序(文本编辑器)不起作用。我知道我必须模糊(或以某种方式刷新),但我已经尝试了很多次,但无法让脚本正常工作。有什么帮助吗 <textarea sname='content' id='redactor'>Ajax updated content</textarea> $(document).ready(function() { var buttons = ['html', 'formatting', 'bold

下面的文本区域是通过ajax调用生成的。但是编辑程序(文本编辑器)不起作用。我知道我必须模糊(或以某种方式刷新),但我已经尝试了很多次,但无法让脚本正常工作。有什么帮助吗

<textarea sname='content' id='redactor'>Ajax updated content</textarea>


$(document).ready(function() {

    var buttons = ['html', 'formatting', 'bold', 'italic', 'deleted', 'unorderedlist', 'orderedlist', 'outdent', 'indent', 'link', 'horizontalrule'];

    $('#redactor').redactor({
        focus: true,
        buttons: buttons,
        maxHeight: 500
    });

});



 $.ajax({
      type: "POST",
      dataType: "json",
      url: "phpVars/ajaxUpload.php", //Relative or absolute path to response.php file
      data: data,
      success: function(data) {
        $(".the-return").html(
         data["form"]
        );  
      }

    });
Ajax更新内容
$(文档).ready(函数(){
变量按钮=['html'、'formatting'、'bold'、'italic'、'deleted'、'unorderedlist'、'orderedlist'、'outdent'、'indent'、'link'、'horizontalrule'];
$(“#redactor”)。redactor({
焦点:对,
按钮:按钮,
最大高度:500
});
});
$.ajax({
类型:“POST”,
数据类型:“json”,
url:“phpVars/ajaxUpload.php”,//response.php文件的相对或绝对路径
数据:数据,
成功:功能(数据){
$(“.return”).html(
数据[“表格”]
);  
}
});

上面是ajax调用

您可以将代码放在函数中:

function loadEditor()
{
    var buttons = ['html', 'formatting', 'bold', 'italic', 'deleted', 'unorderedlist', 'orderedlist', 'outdent', 'indent', 'link', 'horizontalrule'];

    $('#redactor').redactor({
        focus: true,
        buttons: buttons,
        maxHeight: 500
    });
}

$.ajax({
    type: "POST",
    dataType: "json",
    url: "phpVars/ajaxUpload.php",
    data: data,
    success: function(data)
    {
        $(".the-return").html( data["form"] );
        loadEditor();
    }
});

在ajax响应之后,您可以调用这个函数。希望这有帮助。

这是因为当加载编校器的函数时,文本区域还没有数据。您可以尝试将此函数插入ajax函数,或者将ajax提供的数据设置为全局变量

问候

我不明白$(“.return”)指的是什么,但是如果你想更新textarea的内容,你应该通过redactor API:

success: function(data) {
  $("#redactor").redactor('code.set', data["form"] );
}

和ajax响应之后
我想你的意思是在ajax
成功
回调中,我是否只需添加loadEditor();在success中:函数(数据){}?