Laravel collection invalid ordering due AJAX request

Laravel collection invalid ordering due AJAX request

When I try to sort Laravel collection by default sort() function - I got right ordering. But when I try to get this data via Ajax - I got invalid ordering from Ajax response.

When I try to sort Laravel collection by default sort() function - I got right ordering. But when I try to get this data via Ajax - I got invalid ordering from Ajax response.

For example:

 $a = collect([
         '2019-01-10', 
         '2019-01-01', 
         '2019-01-24', 
         '2019-01-03', 
         '2019-01-02'
        ])->sort();

Laravel dd($a) gaves me right ordering:

Collection {#508
  #items: array:5 [
    1 => "2019-01-01"
    4 => "2019-01-02"
    3 => "2019-01-03"
    0 => "2019-01-10"
    2 => "2019-01-24"
  ]
}

But when I tried return this data for jQuery Ajax request:

return response()->json([$a]);

console.log() of ajax response:

0: "2019-01-10"
1: "2019-01-01"
2: "2019-01-24"
3: "2019-01-03"
4: "2019-01-02" 

Invalid ordering

jquery json ajax laravel

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

jQuery ajax get request method example

### jQuery Ajax Get Request Method Example This article is originally published at [https://www.tutsmake.com/jquery-api-ajax-get-method-example/](https://www.tutsmake.com/jquery-api-ajax-get-method-example/...

How to Block and Unblock User in Laravel using Ajax and jQuery

In this Laravel 7 tutorial, you'll learn how to block and unblock user in Laravel using Ajax and JQuery. Admin or master user can block sub user account by using AJAX. How to disabled or Ban User Account by using laravel. How to activate deactivate user login by using laravel with Ajax.

Select2 Ajax Autocomplete in Laravel

select2 ajax json example laravel framework, laravel select2 tags, laravel select2 tables ajax, laravel dynamic autocomplete jquery ajax example, laravel autocomplete from database, laravel autocomplete select2

How to post Form Data using Ajax with jQuery Validation in Laravel 7

In this Laravel 7 tutorial, you will learn how you can post form data to controller using Ajax with jQuery validation in Laravel 7. You can submit the form using jQuery Ajax and without refresh the whole web page. When submitting an Ajax form in Laravel, you will add csrf token in Ajax post request.

Laravel Autocomplete Search With Jquery UI Example

jquery ui autocomplete laravel, jquery ui autocomplete ajax laravel, autocomplete jquery laravel, autocomplete laravel jquery, laravel autocomplete search with jquery ui example, jquery ui autocomplete example