here i am learning jsonp and i have a little problems with a simple code ,
what i am trying to do is a simple jsonp callback but it seems to not working
here is the code:
[index.php]
<html>
<head>
<script type="text/javascript" id="myJSONPCall" src="http://mySubDomain.comoj.com/jsoncall.php?jsonCallback=myCallback"></script>
<script type="text/javascript">
function myCallback(obj) {
alert(obj.text);
}
</script>
</head>
<body>
</body>
</html>
[jsoncall.php]
<?php
$myObject = array(
"text" => "Hello, I am data from the remote server.",
"created_at" => "Thu May 07 21:36:12 +0000 2009"
);
$myJSONObject = json_encode($myObject);
$myJSONCallback = filter_var($_REQUEST['jsonCallback'], FILTER_SANITIZE_STRING);
print "$myJSONCallback($myJSONObject)"
?>
right away , nothing happen.
what exactly goes wrong here?
You need to define your function before calling the url that loads the response
just switch the order your your scripts.