ASP.NET MVC4 &;JQuery - Twitter Feed脚本不工作
ASP.NET MVC4 & JQuery - Twitter Feed Script not working
这是我的确切_Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/Scripts/Tweets.js")
@RenderSection("Scripts",false)
<script type="text/javascript" src="http://cdn.jquerytools.org/1.1.2/full/jquery.tools.min.js"></script>
<script src="../../Scripts/Tweets.js" type="text/javascript"></script>
</head>
<body>
@{
if (ViewBag.IsAdmin ?? false)
{
<div class="controlPanel">
<a href="@Href("~/Post/Edit")">New Post</a>
@Html.ActionLink("Sign Out", "DeAuth", "Account")
</div>
}
else
{
<div class="controlPanel">
@Html.ActionLink("Log In", "Login", "Account")
</div>
}
}
<header>
<a href="@Href("~/")"><img src="@Href("~/Content/Images/gizmologo.png")" alt="Gizmo | Blog Solutions" title="Gizmo | Blog Solutions"/></a>
</header>
<section>
<div id="topSep" class="sep"></div>
<aside>
<img id="picture" width="100" height="100" src="@Href("~/Content/Images/dsykes.jpg")" alt="Picture" title=":P" />
<div id="twitterHeader"><a href="https://twitter.com/Sage0f_Lyricism">D.Sykes on Twitter</a></div>
<div id="tweets">
</div>
<div id="feedLink"><a href="@Href("~/Post/RSS")">RSS Feed</a></div>
</aside>
<div id="main">
@RenderBody()
</div>
<div id="bottomSep" class="sep"></div>
</section>
<footer>
<div id="copyright">Copyright © 2013, Gizmo Bloging</div>
</footer>
</body>
</html>
这里是Tweets.js脚本,不能加载…
$(document).ready(function () {
//$.getJSON("https://twitter.com/statuses/user_timeline.json?screen_name=ninanet&count=5&callback=?", // this is the OLD Twitter json call!
$.getJSON("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=ninanet&count=5&callback=?",
function (data) {
$.each(data, function (i, item) {
ct = item.text;
mytime = item.created_at;
var strtime = mytime.replace(/('+'S+) (.*)/, '$2 $1')
var mydate = new Date(Date.parse(strtime)).toLocaleDateString();
var mytime = new Date(Date.parse(strtime)).toLocaleTimeString();
$("#tweets").append('<div>' + ct + " <small><i>(" + mydate + " at " + mytime + ")</i></small></div>");
});
});
});
我不知道什么可能是问题,我的Jquery是初始化正确,所以是脚本,但我没有得到任何东西。有人能帮帮我吗?
工作演示: http://jsfiddle.net/JTrs7/
酷,如果你试图获取数据跨域尝试使用JSONP
有用链接:(JSONP vs JSON
)
-
JSON和JSONP有什么区别?
-
发送JSONP与JSON数据?
http://bob.ippoli.to/archives/2005/12/05/remote-json-jsonp/
希望能满足你的需求:)
$(document).ready(function () {
var k = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Twitter&include_rts=1&count=5&jsoncallback=";
$.ajax({
dataType: 'jsonp',
url: k,
success: function (data) {
console.log(data);
$.each(data, function (i, item) {
$("#tweetFeed").append("<div class='tweetCloud'><div id='tweetArrow'></div><div id='tweetText'>" + item.text + "</div></div>");
})
}
});
});
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 在Twitter上用ie9中的空白src访问iframe的contentWindow
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 通过javascript/html访问twitter共享iframe
- 使用Javascript获取Twitter访问令牌
- Twitter引导程序Typeahead-Id&标签
- Twitter Bootstrap 2.1.0子菜单在Responsive上看起来很混乱
- 使用FB.ui的Facebook Feed对话给出API错误191
- json twitter query, parse to html feed
- Twitter Feed没有用代码拉入
- CSS覆盖twitter feed小部件
- Twitter Feed API停止工作
- Metro Live Tile Like Twitter Feed with MetroJS
- Twitter feed在页面上添加空白
- ASP.NET MVC4 &;JQuery - Twitter Feed脚本不工作
- 使用Google feed API阅读Twitter RSS
- 获取基于多个标签的Twitter feed
- Twitter Feed与Ember Views的问题
- 如何用JS显示自定义图标而不是个人资料图像的Twitter feed
- 用户认证+ Twitter/Facebook feed (jQuery Mobile/PhoneGap)