使用bookmarklet中的JSONP发生JavaScript错误

时间:2009-08-06 02:36:31

标签: javascript firebug

FireBug Firefox3.5.2中出现以下错误

Failed to load source for: http://example.com/

我的书签

javascript:(
    function(){
        window.callback = function(d){alert(d)};
        var script = document.createElement('script');
        script.setAttribute("type", "text/javascript");
        script.setAttribute("charset", "UTF-8");
        script.setAttribute("id", (new Date()).getTime());
        script.src="http://example.com/api/function.php?callback=window.callback";
        document.body.appendChild(script);
    }
)();

回调是:

window.cb && window.cb({"key":"value"});

怎么了?

1 个答案:

答案 0 :(得分:0)

如果您真的从PHP页面加载,我会确保该页面返回text/javascript MIME类型。