1

Here is my exact _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...

$(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!?

Dezmen Ceo Sykes
  • 179
  • 1
  • 4
  • 16

1 Answers1

1

Working demo: http://jsfiddle.net/JTrs7/

Cool, if you are trying to fetch data cross domain try using JSONP

Helpful links: (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>");
            })
        }
    });
});
Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • I tried using that but it didnt work either, I checked the console for JavaScript and it said "$ is not defined" i dont know what that means – Dezmen Ceo Sykes Apr 26 '13 at 03:15
  • 1
    Actually, that woked!! Awesooome – Dezmen Ceo Sykes Apr 26 '13 at 03:17
  • @DezmenCeoSykes LOL `:))` Glad it helped! Dont forget to accept the answer! see you around! – Tats_innit Apr 26 '13 at 03:23
  • Gotcha bro but wait! how did u do this on fiddle? are there any other example codes? – Dezmen Ceo Sykes Apr 26 '13 at 03:24
  • @DezmenCeoSykes yep bruvoo, did it in fiddle to show the cross domain stuff working for you! there should be heaps look for JSONP + Twitter in search any engine. Keyword is `jsonp` allows JSON object across domain known as **JSON with Padding**. Rest the link above will help you out to understand further. – Tats_innit Apr 26 '13 at 03:26