0

Why I'm not getting any response while using mentionsInput in my Laravel project. data is properly coming in JSON format which I checked properly.

$(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
  });
});
ROOT
  • 11,363
  • 5
  • 30
  • 45
Upasana Chauhan
  • 948
  • 1
  • 11
  • 32

1 Answers1

0

This works for me

$(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);

    }
 });

 }
 });
 });
Upasana Chauhan
  • 948
  • 1
  • 11
  • 32