题
好的...所以我一直都与这一块的鳕鱼现在扭动周围相当长的一段...
第i个使用该代码的工作...
$(document).ready(function() {
$('#content').html('');
$.ajax({
url:'data.json',
dataType: "json",
success: function(data) {
$('#content').append(''+data.rank+'
');
}
});});
在这个代码(它的工作原理)data.json包含在这种格式JSON数据:
{ “USER_ID”: “3190399”, “USER_NAME”: “Anand_Dasgupta” “followers_current”: “86”, “日期date_updated”: “2009-06-04”, “URL”: “”, “阿凡达”: “205659924 / DSC09920_normal.JPG” “follow_days”: “0”, “started_followers”: “86”, “growth_since”:0, “average_growth”: “0”, “明天”: “86”, “next_month”: “86”, “followers_yesterday”: “86”, “等级”:176184, “followers_2w_ago”:空, “growth_since_2w”:86, “average_growth_2w”: “6”, “tomorrow_2w”: “92”, “next_month_2w”: “266”, “followersperdate”:[] }
此数据来自URL:
http://twittercounter.com/api/?username=Anand_Dasgupta&output=json&results = 3 (单击URL来获取数据)
但是,当我在与含有相同数据的URL $就功能取代data.json,这下面的代码似乎没有工作...
$(document).ready(function() {
$('#content').html('');
$.ajax({
url:'http://twittercounter.com/api/?username=Anand_Dasgupta&output=json&results=3',
dataType: "json",
success: function(data) {
$('#content').append(''+data.rank+'
');
}
});});
我此前把这个问题提出在计算器上和反应是,这是一个跨域问题。
因此,我读到跨域AJAX请求,这是我想出了的代码:
$(document).ready(function() {
$('form#search').bind("submit", function(e){
e.preventDefault();
$('#content').html('');
// Define the callback function
function get(jsonData) {
$('#content').append(''+jsonData.rank+'
');
bObj.removeScriptTag();
}
// The web service call
var req = 'http://twittercounter.com/api/?username=Anand_Dasgupta&output=json&results=3&callback=get';
// Create a new request object
bObj = new JSONscriptRequest(req);
// Build the dynamic script tag
bObj.buildScriptTag();
// Add the script tag to the page
bObj.addScriptTag();
});
});
但是,即使不似乎是工作。
如果任何人都可以提供任何帮助那么它将被深深理解。 我已经给整个代码,使任何人都可以在自己身上试验,如果他们想。
感谢您 阿南德