【问题标题】:Why I am not getting any response while using mentionsInput in my laravel project为什么在我的 laravel 项目中使用mentionsInput 时没有得到任何响应
【发布时间】:2020-06-15 21:42:20
【问题描述】:

为什么在我的 Laravel 项目中使用 mentionsInput 时没有得到任何响应。数据以JSON 格式正确输入,我已正确检查。

$(document).ready(function() {
  var token = $("#csrf-token").val();
  $("textarea.mentions").mentionsInput({
    source: function(request, response) {
      $.ajax({
        url: "/snippets/getcommentedusers",
        type: "POST",
        dataType: "json",
        data: { _token: token },
        error: function(error) {
          console.log(error);
        },
        success: function(data) {
          //   alert(data);
          //   response(data);
          data = _.filter(data, function(item) {
            return item.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
          callback.call(this, data);
        }
      });
    },
    showAtCaret: true
  });
});

【问题讨论】:

  • 你得到的格式是什么?是纯文本吗?
  • 报错成功无响应
  • 您可以将错误添加到您的问题中吗?这将有助于解决您的问题。
  • 我很惊讶,即使我没有收到任何错误!
  • 也许您的代码库已禁用错误,您是否还可以检查日志中是否有错误?

标签: jquery ajax input mentionsinput.js


【解决方案1】:

这对我有用

$(document).ready(function(){

var token = $("#csrf-token").val();
var snippet_id = $("#snippets_id").val();

$('textarea.mention').mentionsInput({
onDataRequest:function (mode, query, callback) {

$.ajax({
    url: '/snippets/getcommentedusers',
    type: "POST",
    dataType: "json",
    data: {'_token': token,'snippet_id':snippet_id},
    error: function (error) {
    console.log(error);
    },
    success: function(data){

      data = _.filter(data, function(item) { return item.name.toLowerCase().indexOf(query.toLowerCase()) > -1 });

      callback.call(this, data);

    }
 });

 }
 });
 });

【讨论】:

    猜你喜欢
    • 2022-01-11
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    • 2023-01-19
    • 2020-05-16
    • 1970-01-01
    • 2016-07-14
    相关资源
    最近更新 更多