简体   繁体   English

ivirabyan / jquery-mentions如何检查ajax请求响应

[英]ivirabyan/jquery-mentions how to check ajax request respone

I am using ivirabyan/jquery-mentions in my project. 我在我的项目中使用ivirabyan / jquery-mentions。 i can do ajax request, but the problem is how can i use the response 我可以执行ajax请求,但问题是我如何使用响应

$('textarea.mentions').mentionsInput({
    source: function( request, response ) {

        $.ajax({
            url: rootPath() + "user/tagFriends/" + request.term,
            type: "GET",
            dataType: "json",

            success: function(data){
              alert(data);
              // found data here
            }
        });
    },
    showAtCaret: true

});

Thanks in advance. 提前致谢。

You can try this code, it may work 您可以尝试此代码,它可能会起作用

$('textarea.mentions').mentionsInput({
source: function( request, response ) {

    $.ajax({
        url: rootPath() + "user/tagFriends/" + request.term,
        type: "GET",
        dataType: "json",

        success: function(data){
          response(data);
          // Just add this line
        }
    });
},
showAtCaret: true
}); 

You can try this: 您可以尝试以下方法:

$.ajax({
            url: rootUrl + '/your_controller/',
            type: "GET",
            contentType: 'application/json',
            // YOUR DATA COMING FROM THE VIEW TO THE CONTROLLER (IF IT NEED IT).
            data: "{ 'id':'" + id + "', 'user': '" +user+ "'}",
            dataType: 'json',
            success: function (result) {
                if (result) {
                 //DO YOUR STUFF. FOR EXAMPLE. SHOWING A DIV
                 $('#your_div').append("<div>Hi there. Controller send this: "+data+"</div>");
                 // IF YOR DATA IS AN OBJECT. YOU CAN ACCESS DIRECTLY.
                 // data.attribute1, data.attribute2,...
                 // EQUALS FOR A LIST OF OBJECT AFTER LOOP IT.
                } else {
                  //DO YOUR STUFF
                }
            },
            failure: function (data) {
                // DO YOR STUFF IN FAILURE CASE.
            },
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM