获取 jquery 函数来处理 ajax 调用?

Getting a jquery function to work with an ajax call?

以下文本区域是通过 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调用

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

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提供的数据设置成一个全局变量。

此致!

我不明白 $(".the-return") 指的是什么,但是如果你想在 ajax:success 上更新 textarea#redactor 的内容 - 你应该这样做通过编辑 API:

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