Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Simplifying Ajax Requests Using HTML attributes
Elitejax is a standalone javascript library that makes AJAX requests a lot more easier without you writing a single line of javascript.
All you have to do is add data-elitejax="true" attribute to your form tag and you are good to go
<form data-elitejax="true" name="spotify" action="https://api.spotify.com/v1/search" method="get">
Enter Artist name: <input type="text" name="q"><br />
<input type="hidden" name="type" value="artist">
<input type="submit" value="Submit">
</form>
<!-- include elitejax library from bower components directory -->
<script src="bower_components/elitejax/build/elitejax.min.js" charset="utf-8"></script>
You can install this library by cloning this git and reference the javascript files from the build directory, using npm:
npm install elitejax --save
or using bower:
bower install elitejax
NB: You can't load elitejax as a node module
To exclude a form field in your form from your AJAX request, you can add data-ej-x attribute to that field, like:
<!-- below form field will be ignored -->
<input type="input" data-elitejax-x />
Due to elitejax's flexibility, you can add custom configuration for each form in your webpage. First specify a name for your form and then use it with ej.configure, like so:
<form data-elitejax="true" name="spotify" action="https://api.spotify.com/v1/search" method="get">
.....
</form>
<!-- include elitejax library from bower components directory -->
<script src="bower_components/elitejax/build/elitejax.min.js" charset="utf-8"></script>
<script type="text/javascript">
elitejax.configure('spotify'[, {configuration}]);
</script>
The configuration object argument for the configure method takes 4 parameters:
async default: true : You can set this to true or false
cType default: "application/json" : This is the content type header.
resType default: "json" : This is the response type of the AJAX query, you can use jsonp for cross domain requests.
callback default: function : The default callback logs the data to the console. You can specify your callback function for when the request completes successfully
You can use the elitejax ajaxIt method to send a custom AJAX request:
elitejax.ajaxIt(url, method, data[, requestName]);
So, we can customize the spotify API call to run on page load instead of depending on user interaction like so:
<script src="bower_components/elitejax/build/elitejax.min.js" charset="utf-8"></script>
<script type="text/javascript">
window.onload = function () {
var data = {
q: 'Justin',
type: 'artist'
}
elitejax.ajaxIt('https://api.spotify.com/v1/search', 'get', data, 'spotifyCustom');
}
</script>
Elitejax is Licensed under the MIT License
Please do! Send a pull request after your modifications.
Sharing is caring.... make sure to let your peers know.
FAQs
Simplifying Ajax Requests Using HTML attributes
We found that elitejax demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.