First of all, you cannot make a POST request using JSONP.
What basically happens is that a script tag has been dynamically added to load your data. Therefore, only GET requests are possible.
In addition, your data should be wrapped in a callback function, which is called after the request is completed to load the data into a variable.
The whole process is handled by jQuery for you. Just using $ .getJSON in an external domain does not always work. I can talk about personal experiences.
Best to add & callback =? to you url.
On the server side, you need to make sure your data is wrapped in this callback function.
t
echo $_GET['callback'] . '(' . $data . ')';
EDIT:
I don’t have enough reviews to comment on Liam’s answer, so the solution is here.
Replace Liam Line
echo "{'fullname' : 'Jeff Hansen'}";
from
echo $_GET['callback'] . '(' . "{'fullname' : 'Jeff Hansen'}" . ')';
Ewout Kleinsmann Jul 24 '11 at 19:25 2011-07-24 19:25
source share