Get the URI passed to the ajax call

Get the URI passed to the ajax call

luca.gluca.g Posts: 12Questions: 3Answers: 0

Is it possible to get the URI passed by the ajax option? For instance, here:

var table = $('#events').DataTable({
                "ajax":     {
                  "url": "get_results.php",
                  "type": "get",
                  "data": function ( d ) {
                    return $.extend( {}, d, {
                      "search_location": localStorage.getItem('search_location'),
                      [other extra data I'm appending....]
                    } );
                  }
                },

I see my XHR get call with all its parameters. I'd like to save that string to localStorage for using it later (e.g. for when the user returns to that page).

Replies

  • allanallan Posts: 61,711Questions: 1Answers: 10,103 Site admin

    Would this work for you?

                    var sentData;
                    var table = $('#events').DataTable({
                    "ajax":     {
                      "url": "get_results.php",
                      "type": "get",
                      "data": function ( d ) {
                        var data = $.extend( {}, d, {
                          "search_location": localStorage.getItem('search_location'),
                          [other extra data I'm appending....]
                        } );
    
                        sentData = data;
    
                        return data;
                      }
                    },
    

    Allan

  • luca.gluca.g Posts: 12Questions: 3Answers: 0
    edited October 2022

    Thank you Allan, got it:

                        sentData = data;
                        console.dir(sentData);
                        return data;
    
Sign In or Register to comment.