2013-07-04 26 views
0

我有一个c:\index.html和使用定义JSONP调用的jQuery:Mocktest本地JSONP抛出parseerror “回调不叫”

var url = 'http://localhost:8080/test/jsonServlet' 
if (mockTest) 
    url = 'file:bla.json'; 
jQuery.ajax({ 
    type: "POST", 
    url: url, 
    dataType: 'jsonp', 
    error: function(a,b,c) { 
    console.debug("ERR", b, c); 
    } 
}); 

c:\bla.json是这样的:

var f = this.jQuery.expando; 
console.debug("BLA", f); 
f = this[f].handle; 
console.debug("TYPE", typeof f); 
f({'decoration':'Hello World!'}); // call the callback! 

有三条消息:

BLA jQuery1705534191443584859 
TYPE function 
ERR parsererror jQuery1705534191443584859_1372951198352 was not called 

回答

0

我叫jQuery1705534191443584859而不是jQuery1705534191443584859_1372951198352

现在的作品,我用:

var f; 
    for (var k in this) 
     if (this.hasOwnProperty(k) 
      && k.indexOf(this.jQuery.expando) > -1 
      && k.indexOf('_') > -1) 
      f = k; 

    this[f]({'decoration':'Hello World!'}); 

现在,当地的模拟测试工作。