Workflow failed: TypeError: $.ajax is not a function

I have this function inside the server side action in creating a plugin:

function(properties, context) {
    var $ = require("jquery");
    
    var settings = {
      "url": "https://api.konnektive.com/order/query/?params",
      "method": "GET",
      "timeout": 0,
      "headers": {
        "Content-Type": "application/json"
      },
    };

    $.ajax(settings).done(function (response) {
      console.log(response);
    });
}

with this node module:

{
    "dependencies": {
        "jquery": "latest"
    }
}

and it’s a simple ajax request to fetch data. But I’m getting the $.ajax is not a function error which is weird since jquery has ajax by default. Am I missing something here?

jquery is a client side library.
If you need to fetch resources you can use context.request, that is a sync method, or require other packages like for example axios.
Remember that anything async needs to go inside context.async.

1 Like