Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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
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
If your request returns data as JSON, you can add to the DOM from that object without javascript using the data-post
and data-postTo
attributes in your form element.
The data-post
attribute is used to specify what part of the data returned you want to use.
data-postTo
is the DOM selector of where to post the resulting value.
<!-- using the spotify API -->
<div class="result"></div>
<form name="spotify" data-elitejax="true" action="https://api.spotify.com/v1/search" data-post="artists.items[1].name" method="get" data-postTo=".result" >
Enter name: <input type="text" name="q"><br />
Category: <input type="text" name="type" value="artist"><br />
<input type="submit" value="Submit">
</form>
<script src="path/to/elitejax.min.js" charset="utf-8"></script>
The above will place the result in the div element with .result class.
To exclude a form field in your form from your AJAX request, you can add data-elitejax-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
The npm package elitejax receives a total of 1 weekly downloads. As such, elitejax popularity was classified as not popular.
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 uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.