javascript - How do I implement an 'order' property with AJAX data? -


i making asynchronous 'get' request using parse api. ajax request returns array of strings may not in right order. have searched on google 'order' property ajax may possess no luck.

this ajax request function called retrieve getting value of text property.

ajax request:

obj.retrieve = function(callback) {    $.ajax({        url : 'https://api.parse.com/1/classes/messages',        type : 'get',        datatype: 'json',        contenttype : 'application/json',        data : json.stringify({               text : 'value: ',            order: "-createdat"          // order property go here?                }),        error : function(data) {            console.log('error: ' + data);        },        success : function(data) {           (var = 0; < data["results"].length; i++)              callback(data["results"][i].text);        }    }); };  

tl;dr: each object has field names createdat, updatedat, , objectid parse. ideally, use createdat order. suggestions?

possible solutions:

  1. sort on server side

  2. sort manually:

    data['results'].sort(function(a, b) {     return a.createdat < b.createdat ? -1 : 1; }); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -