Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonp

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonp

A sane JSONP implementation.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
551K
increased by0.4%
Maintainers
2
Weekly downloads
 
Created

What is jsonp?

The jsonp npm package is a simple JSONP implementation for making cross-domain requests in JavaScript. JSONP (JSON with Padding) is a technique used to overcome the limitations of the same-origin policy in web browsers, allowing you to request data from a server in a different domain.

What are jsonp's main functionalities?

Basic JSONP Request

This feature allows you to make a basic JSONP request to a specified URL. The callback function is automatically appended to the URL, and the response is handled in the provided callback function.

const jsonp = require('jsonp');

const url = 'https://api.example.com/data?callback=callbackFunction';

jsonp(url, null, function (err, data) {
  if (err) {
    console.error(err.message);
  } else {
    console.log(data);
  }
});

JSONP Request with Options

This feature allows you to make a JSONP request with additional options such as a custom callback parameter name and a timeout duration. The options object can be used to customize the request.

const jsonp = require('jsonp');

const url = 'https://api.example.com/data';
const options = { param: 'customCallback', timeout: 5000 };

jsonp(url, options, function (err, data) {
  if (err) {
    console.error(err.message);
  } else {
    console.log(data);
  }
});

Handling JSONP Errors

This feature demonstrates how to handle errors in a JSONP request. If an error occurs, it is passed to the callback function as the first argument, allowing you to handle it appropriately.

const jsonp = require('jsonp');

const url = 'https://api.example.com/data?callback=callbackFunction';

jsonp(url, null, function (err, data) {
  if (err) {
    console.error('Error occurred:', err.message);
  } else {
    console.log('Data received:', data);
  }
});

Other packages similar to jsonp

FAQs

Package last updated on 19 Mar 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc