我正在尝试使用以下代码使 JSONP 响应正常工作...
$http.jsonp('http://example.com:8888/?callback=JSON_CALLBACK').success( function( response )
{
console.dir( response );
});
http://example.com:8888/?callback=JSON_CALLBACK通过 node.js 返回以下内容
JSON_CALLBACK({ 日期:'2013-05-15T08:53:51.747Z' });
像这样在 node.js 中设置标头....
res.writeHead(200, {'Content-Type': 'application/json'});
然而,我在 Chrome 控制台中遇到的错误是……
Uncaught ReferenceError: JSON_CALLBACK is not defined
然而,奇怪的是,如果我创建window.JSON_CALLBACK(response)
它会运行的函数。但我认为成功是为了代表我做到这一点。