Backendless._ajax() in JS SDK

Can one use the “Backendless._ajax()” method in the JS SDK directly in JS and Node.JS code? If so, is there any documentation about how to do this, in particular about the “asyncHandler” attribute of the config argument and what that should be?

Thanks.

Hi, Rick,
This function is used internally by SDK to handle all the request-response routine for you, enabling you with much more convenient SDK methods. It is not supposed to be used directly, so we don’t put it into documentation.
Sure you have access to this function just like to any other function in backendless.js and you can use it in your code, but why would you need that? I can’t see how you would possibly take any real advantage of it.
Regards,
Sergey

Thanks.

The reason I ask is just that this may be a convenient way to add the ajax capability required to access Node.js scripts in Backendless from a browser.

Rick,

Sounds like you’re asking about invoking a script from the browser-side, although the original question was “scoped” to both JS and Node.JS.

From the browser side it could also be the good ol’ jQuery to invoke your Node.JS scripts.

Cheers,
Mark

Indeed, the case I mentioned would be client (browser) side. But is my understanding correct that one could include the Backendless JavaScriptsSDK (or has it available) server-side for Node.js scripts? In that situation, it seems the unified functionality of Backendless._ajax() might simplify things.

I also fully agree that in many/most cases jQuery would be preferred. There are some cases though, such as if one wants to incorporate a payments gateway, where one would prefer to not include a package like jQuery, or even AngularJS, that essentially allows arbitrary hidden manipulation of the DOM if possible.

That’s not to assume the Backendless javascript SDK would necessarily be better. However, a quick scan suggests it doesn’t include significant DOM manipulation features. Even if that proves to not be the case, it seems one could use it as a model, at least to the module API level, for a compatible and simplified AJAX capability rather than jQuery.

Finally, it seems one could also use the NPM “browser-request” module if one is using Browserify to build a javascript client to talk to Backendless. But then that’s yet another level of complication that one might like to avoid if possible in some situations.

As you might have already seen, Backendless Javascript SDK simply uses XMLHttpRequest inside to make a request, and the rest of the code in _ajax() function is responsible for setting application headers, parsing response, setting some values to cache etc. - all the things that make your work with Backendless API a lot easier.
But you don’t need all this overhead to call hosted scripts. You can use the same native XMLHttpRequest and I believe it’ll keep your code clean and lacking unexpected side-effects.