Advertise with us

JSONP

What is Jsonp? Difference between Json and Jsonp ?

Last updated:7/3/2018 11:22:55 PM

2 Answers

Prakash nidhi Verma
Prakash nidhi Verma

JSONP :

JSONP means JSON with Padding. 

JSONP does not use the XMLHttpRequest object.

JSONP uses the <script> tag instead.

Requesting an external script from another domain does not have this problem.

JSONP uses this advantage, and request files using the script tag instead of the XMLHttpRequest object. 

Syntax:

<script src="demo_jsonp.php"> 


Server File :

 <?php 
$myJSON = '{ "name":"Prakash", "age":19, "city":"Allahabad" }';
echo "myFunc(".$myJSON.");";
?>


Callback Function:

function clickButton() { 
    var s = document.createElement("script");
    s.src = "jsonp_demo_db.php?callback=myDisplayFunction";
    document.body.appendChild(s);
}

Answer