我试图从CNet的api中提取数据,api被拉到网页,因为当我检查元素时,响应在网络中,但它没有显示在控制台中。
<script src="jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: "http://developer.api.cnet.com/rest/v1.0/techProductSearch",
type: "get",
data: { viewType:"json", iod: "none", callback: "phone", partKey:"2nnae6wsj2w72yqhcwu4v7sg", partTag:"2nnae6wsj2w72yqhcwu4v7sg", query: "ipod", productId:"31303113" },
dataType: "jsonp"
});
});
function ipod(data) {
console.log(data);
}
</script>
答案 0 :(得分:0)
您尚未指定jQuery成功完成后要执行的操作。我猜是执行ipod功能;但是jQuery不能
所以,这应该做
$(document).ready(function(){
$.ajax({
url: "http://developer.api.cnet.com/rest/v1.0/techProductSearch",
type: "get",
data: { viewType:"json", iod: "none", callback: "phone", partKey:"2nnae6wsj2w72yqhcwu4v7sg", partTag:"2nnae6wsj2w72yqhcwu4v7sg", query: "ipod", productId:"31303113" },
dataType: "jsonp",
success: ipod
});
答案 1 :(得分:0)
您需要将ajax的结果绑定到方法..
使用.done()
方法
$.ajax({
url: "http://developer.api.cnet.com/rest/v1.0/techProductSearch",
type: "get",
data: { viewType:"json", iod: "none", callback: "phone", partKey:"2nnae6wsj2w72yqhcwu4v7sg", partTag:"2nnae6wsj2w72yqhcwu4v7sg", query: "ipod", productId:"31303113" },
dataType: "jsonp"
}).done(ipod);