我读了一篇post about making JSON calls (with jQuery) safer by adding a dataFilter to parse the returned string .
但是在帖子中对此进行了解释(更具体地说,在从上述帖子链接的上一篇帖子中):
It’s important to note the removal of the dataType parameter in the $.ajax() code above. This is required in order to prevent a double-eval of service responses containing only a single string.
Internally, jQuery uses a combination of the dataType parameter and the implicit type the response. If the dataType is "json" and typeof(response) is “string”, then jQuery uses eval() to deserialize the response.
但是由于我正在进行跨域调用,因此我无法删除 dataType,必须将其设置为 json[p] 以允许调用。但是通过这个设置,dataFilter 不会被调用,有没有办法在不编辑 jQuery 内部的情况下过滤数据?
如果我错过了任何重要的事情,请询问。
谢谢, 克里斯·M
最佳答案
jsonp 实现通过将 SCRIPT 标记注入(inject)文档头部来实现其跨域魔法。在评估响应之前,您无法放入过滤器来解析该响应。
关于jQuery 1.3.2 + JSON + 跨域: How to filter the returned data?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1496943/