jQuery 1.3.2 + JSON + 跨域: How to filter the returned data?

标签 jquery json

我读了一篇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/

相关文章:

javascript - ASP.NET MVC 通过单击按钮创建新的 Guid

jquery - 如何获取这段代码中的data-id值

jackson json 和 spring 和 hibernate 的 java.lang.StackOverflowError

java - Java 中的多个数组和对象 JSON

java - 使用 Jackson 转换器将嵌套的 json 绑定(bind)到 @RequestBody 对象

java - Autobean 和 XSS 问题

Javascript 图像缩放 (JQuery)

javascript - jQuery sum TD 点击事件

javascript - jquery .each() 只做最后一个元素

r - 提取嵌套在列表内的 data.frame