I am calling a service that return json data.
script:
$.ajax({
type: "POST",
url: "/some/service",
dataType: "json",
success: function(response) {
if (response.status == "ok" && response.messages.length > 0) {
// obj is a jQuery object
obj.trigger(SOME_EVENT, response.messages);
}
}
});
this is the response example:
{
"status":"ok",
"messages":[
{"id":1,"message_text":"latihan"},
{"id":123,"message_text":"hello"}]
}
when obj received the SOME_EVENT trigger, I am expecting it to pass messages data below:
[{"id":1,"message_text":"latihan"},
{"id":123,"message_text":"hello"}]
but when I printed messages parameter to console,
// on receiving messages
obj.bind(SOME_EVENT, function(sender, messages) {
console.log(messages);
});
turn out, it only passed the last message below
{"id":123,"message_text":"hello"}
anyone can explain why the array of messages is not passed by my custom event?