Pak Jiddat - Innovative Software Services

Read: In the name of thy Lord Who createth, Createth man from a clot. Read: And thy Lord is the Most Bounteous, Who teacheth by the pen, Teacheth man that which he knew not. Nay, but verily man is rebellious That he thinketh himself independent!. Lo! unto thy Lord is the return. (Sura Alalaq 96:8)

Making cross domain Ajax calls using JSONP

Created On: 29 Mar, 2017: 17:03:55 - Tags : javascript | security


JSONP stands for JSON Padding. It allows scripts to make requests to JavaScript files on domains different from the original domain.

JSONP works by adding the required URL to a HTML script tag. This is typically done by manipulating the HTML DOM using a technique known as script element injection. The script tag is allowed to access files from other domains.

The URL of the required JavaScript file should contain a callback parameter which has the name of a JavaScript function. This function is called when the contents of the file are fetched. The response from the server is basically a call to the callback function. The JSON data is given as parameters to this function.

The browser executes the response from the server. The callback function is defined on the page that makes the Ajax call.

Related Articles

  1. Preventing spam messages with Contact Form 7 WordPress plugin
  2. Generate Certificate Signing Request (CSR) for ssl certificates
  3. Whitelisting devices and files for RKhunter
  4. Using Oauth2l
  5. Use of Preflight request in HTTP Cross Origin Resourse Sharing (CORS)
  6. Adding event listeners using JavaScript
  7. Using Prefetch, Preload and Preconnect for speeding page load times
  8. Get current unix timestamp using Javascript
  9. Fetching html elements using CSS selectors with Javascript
  10. Fetching html elements using CSS class names
  11. Fetching parent node element of a HTML node
  12. Adding option to html selectbox using Javascript
  13. Changing CSS styles using Javascript
  14. Allowing Cross Origin Requests using htaccess
  15. NodeJs permission denied error
  16. Customizing Redmine layout
  17. Passing parameters to Jquery event handler function
  18. W3C.Data
  19. Using cookies in Javascript
  20. Javascript JSON guide
  21. Convert javascript object to json string
  22. Javascript date object
  23. Get the time using JavaScript
  24. Using keydown event handler for detecting enter key press
  25. Get co-ordinates of element relative to document using Jquery
  26. Using clearTimeout and onmouseenter, onemouseleave events
  27. Replacing a string using Javascript replace function
  28. Base64 Encoding of utf-8 encoded string using Javascript
  29. Setting CSS styles using JQuery
  30. Replacing html element using replaceWith jquery function
  31. Iterate throught Javascript object properties
  32. Select contents on text field