相关疑难解决方法(0)

未捕获的TypeError:属性...不是函数 - 页面加载后

我正在使用跨域Ajax请求到外部API.每隔一段时间它就会失败,并显示控制台消息:

Uncaught TypeError: Property 'photos' of object [object DOMWindow] is not a function
Run Code Online (Sandbox Code Playgroud)

查看返回的JSON,它是有效的JSON,因此它不是外部API的错误.

我无法可靠地重现错误:似乎触发错误的唯一因素是我快速重复地调用请求.

在这种情况下,当用户移动Google地图时(我向地图添加标记),我会调用Ajax请求,如果用户移动得太快,就会发生这种情况.

以下是我的代码的相关部分:

// Code located inside an external JS file referenced inside the head
// Not wrapped inside document.ready - but all the code setting up 
// the map (calling a function which calls a function which adds the 
// tilesloaded listener) *is* inside document.ready
function addMarkers() {
    var pm_url = "http://www.cyclestreets.net/api/photos.json?key=" + MY_KEY;
    $.ajax({
       url: pm_url,
       crossDomain: true, 
       contentType: "application/json",
       dataType: 'jsonp',
       data: pmdata, …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery jsonp

6
推荐指数
1
解决办法
9580
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

jsonp ×1