Sachin Singh

Sachin Singh

  • 7
  • 55.8k
  • 82.8k

How JsonP media type formatter actually works?

Sep 5 2020 12:17 AM
JsonP wraps json data into a function , browser allows script to load from other domain so cross origin request is possible with jsonp.
 
However, without any Callback defined , how are we able to get Json data back in Ajax Success.
  1. function getEmployeeById() {  
  2.           
  3.           $.ajax({  
  4.               "type""get",  
  5.               "url": myUrl,  
  6.               "data":{Id:id},  
  7.               "dataType""Jsonp",  
  8.               "cache"false,  
  9.               "success"function (data) {  
  10.                    
  11.               },  

  12.           })  
  13.       } 
 Obvioulsy , web API would be sending jsonp formatted data otherwise browser would not allow it , My question is, i have not defined any callback function to get Jsonp data and Success function is getting json object, how is the whole process working?
It seems as if web api is sending plain Json object without wrapping it in function , how?

Answers (2)