2014-09-01 115 views
0

我正在尝试使用下面的代码进行Ajax调用。相同的代码适用于闪烁r api。但不知道为什么这不起作用,并返回此网址的任何结果。有人可以帮忙吗?Ajax调用不返回任何数据

var URL2='https://www.ibm.com/gateway/?&cc=br&lc=pt&format=json&ts=1340215931434&type=getExpertProfile&userid=30469&cb=200:displayData';     



$.ajax({ 
    url: URL2, 
    // contentType: "application/json; charset=utf-8", 
    dataType: "jsonp", 
    jsonp: "callback", 
    jsonpCallback: "jsonpCallbackfunction", 
    success: function (data) { 
     console.log('on success!'); 
     console.log(data); 
    }, 
    error: function (xhr, ajaxOptions, thrownError) { 
     console.log('on error!'); 
     console.log("xhr.status: " + xhr.status); 
     console.log("xhr.statusText: " + xhr.statusText); 
     console.log("xhr.readyState: " + xhr.readyState); 
     console.log("textStatus: " + textStatus); 
     console.log("errorThrown: " + errorThrown); 
     console.log("xhr.redirect: " + xhr.redirect); 
    } 
}); 
+0

你正在做* POST *的权利?也许是由于使用'jsonp'... – 2014-09-01 20:31:28

+0

你有'url:'URL2''而不是'url:URL2' – Stryner 2014-09-01 20:33:49

回答

0

试试这个

$.ajax({ 
    url: 'URL2', 
    //contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    //jsonp: "callback", 
    //jsonpCallback: "jsonpCallbackfunction", 
    success: function (data) { 
     console.log('on success!'); 
     console.log(data); 
    }, 
    error: function (xhr, ajaxOptions, thrownError) { 
     console.log('on error!'); 
     console.log("xhr.status: " + xhr.status); 
     console.log("xhr.statusText: " + xhr.statusText); 
     console.log("xhr.readyState: " + xhr.readyState); 
     console.log("textStatus: " + textStatus); 
     console.log("errorThrown: " + errorThrown); 
     console.log("xhr.redirect: " + xhr.redirect); 
    } 
}); 
+0

试图没有任何东西正在返回 – user244394 2014-09-01 20:39:34

+0

如果你直接去url直接得到什么? – kefy 2014-09-01 20:48:05

+0

你不能使用json跨域。 “jsonp”在这里使用是正确的。 – Antiga 2014-09-01 20:48:40

0

您正在使用您的网址,而不是指向变量的字符串。在下面尽量少尝试一下。

$.ajax({ 
    url: URL2, 
    dataType: "jsonp", 
    success: function (data) { 
     console.log('on success!'); 
     console.log(data); 
    }, 
    error: function (xhr, ajaxOptions, thrownError) { 
     console.log('error'); 
    } 
}); 

如果仍然失败,您应该查看正在进行的网络调用以及来自服务器的响应。 (在这种情况下,IBM)这里的客户端代码很好,但它仍然依赖于在另一端正确设置的东西。它也依赖于你调用正确的URL。