Hello.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Test JSONP</title> <script type="text/javascript" language="javascript"> var callbacks=new Object(); function getJSONP(url,cb) { var i; do i='c'+Math.floor(Math.random() * 99999); while(callbacks[i]); callbacks[i] = function(obj) { cb(obj); delete callbacks[i]; }; var script=document.createElement('script'); script.src=url+(url.indexOf('?')>=0?'&':'?')+'callback=callbacks.'+i; script.type='text/javascript'; document.body.appendChild(script); } </script> </head> <body> <script type="text/javascript"> // Callback function onSuccess(user) { alert(user); } </script> <input type="button" value="Получить JSONP" onclick="getJSONP('http://vkontakte.ru/feed2.php',onSuccess)"/> <div id="result"></div> </body> </html>
This code for some reason writes an error Uncaught Syntax Error: Unexpected token :
What can be wrong?