codeworth-gh / PSPS

Play+Slick+Postgres Stack seed project
Apache License 2.0
5 stars 0 forks source link

Allow Playjax to use jQuery as well #18

Closed michbarsinai closed 3 years ago

michbarsinai commented 6 years ago

At the moment, Playjax only supports fetch. We have code that makes it easy to use jQuery as well:

  function ajaxData( call, data ) {
        var retVal = {
            url: call.url,
            type: call.type,
            dataType: "json",
            contentType: "application/json; charset=utf-8"
        };
        if ( typeof(data) !== "undefined" ) {
            retVal.data = JSON.stringify(data);
        }
        return retVal;
    }

Used like this:

$.ajax(
    ajaxData(
            jsRoutes.controllers.IndexCtrl.apiCalculateIndexValues(),
            collectDataMaps()   
     )
).done(function(data){
 ...

Need to add it to Playjax, in a way that' s inline with it's current API. Then add a demo code for this on the first page, below the JS6 fetch code demo.

⚠️ Note 1 that Playjax should not depend on jQuery, just generate the object needed for jQuery's ajax method. ⚠️ Note 2 The above ajaxData snippet should be updated to include the CSRF value, if one exists. See the Playjax code for how it's done for JS6.

michbarsinai commented 3 years ago

Closing as JQuery is optional on most modern configurations,