我在我的项目中使用ivirabyan / jquery-mentions。我可以做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
});
提前致谢。
答案 0 :(得分:3)
您可以尝试使用此代码,它可能会起作用
$('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
});
答案 1 :(得分:1)
你可以试试这个:
$.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.
},
});