I am trying to get a JSONP response working using the following code...
$http.jsonp('http://example.com:8888/?callback=JSON_CALLBACK').success( function( response )
{
console.dir( response );
});
http://example.com:8888/?callback=JSON_CALLBACK returns the following via node.js
JSON_CALLBACK({ date:'2013-05-15T08:53:51.747Z' });
The header is being set in node.js like this....
res.writeHead(200, {'Content-Type': 'application/json'});
Yet the error I get in a Chrome console is this...
Uncaught ReferenceError: JSON_CALLBACK is not defined
However, weirdly, If I create the function window.JSON_CALLBACK(response)
it will run. But I thought that success is meant to do that on my behalf.
Your content-type header is not correct.
Use application/json
if what you return is plain JSON. JSONP is Javascript, so you should use application/javascript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With