简体   繁体   English

ASP.NET MVC4和JQuery-Twitter Feed脚本不起作用

[英]ASP.NET MVC4 & JQuery - Twitter Feed Script not working

Here is my exact _Layout.cshtml 这是我确切的_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 &copy; 2013, Gizmo Bloging</div>      
    </footer>


</body>
</html>

And here is the Tweets.js Script that wont load... 这是不会加载的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>");
        });
    });

});

I dont know what could be the problem, my Jquery is initialized properly and so is the script but i dnt get anything.. Can someone pleeease help!? 我不知道可能是什么问题,我的Jquery正确初始化了,脚本也是如此,但是我没有得到任何东西。有人可以帮忙吗?

Working demo: http://jsfiddle.net/JTrs7/ 工作演示: http : //jsfiddle.net/JTrs7/

Cool, if you are trying to fetch data cross domain try using JSONP 太酷了,如果您尝试跨域获取数据,请尝试使用JSONP

Helpful links: ( JSONP vs JSON ) 有用的链接:( JSONP vs JSON

Hope it fits your needs :) 希望它能满足您的需求:)

Sample code 样例代码

$(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>");
            })
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery日期选择器在ASP.Net MVC4中无法正常工作 - jQuery date picker is not working properly in ASP.Net MVC4 视图中添加的ASP.NET MVC jQuery脚本不起作用 - ASP.NET MVC jQuery script added in View not working 使用Ajax和jQuery的ASP.NET MVC4中的自动完成文本框 - Autocomplete textbox in asp.net mvc4 using ajax and jQuery 使用ASP.net mvc4将文本转换为HTML - text to HTML with ASP.net mvc4 ASP.Net MVC4返回带有目录列表的html页面,而不是其内部javascript脚本文件 - ASP.Net MVC4 return html page with directory listing instead of its internal javascript script file 包括特定于ASP.NET MVC4视图或部分视图的脚本 - Including script specific to an ASP.NET MVC4 view or partial view 如何在asp.net mvc4中使用javascript或jquery获取HTML div的打印 - how to get print of html div using javascript or jquery in asp.net mvc4 如何使用 JQuery 和 ASP.NET MVC4 在按钮单击时返回要下载的 Excel 文件 - How to return a Excel file to be downloaded on button click using JQuery and ASP.NET MVC4 ASP.NET MVC4-jQuery jqFancyTransitions错误:TypeError:$(…).jqFancyTransitions不是函数 - ASP.NET MVC4 - JQuery jqFancyTransitions error: TypeError: $(…).jqFancyTransitions is not a function 不使用Json和Jquery在Asp.net MVC4中级联下拉列表 - Cascading Dropdown List in Asp.net MVC4 using Json and Jquery not Populate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM