Hello, everyone. I am working on an application that I think I may need a little help. Yes, I am new to this language so I hope you won't be to hard on me. I am sure this is something stupid (mistake) but if someone would lean a helping hand that would be greatly appreciated.

With this application I am using JSON (JSONP - callback=?). Here is my code:

 $.support.cors = true;     
        $(document).ready(function(){
            var tweet = "";
            // Handle the search button's click event
            $("#btnSearch").click(function() {
                // Reset the div element in case a second search is made
                $("#tweets").html("");

                var searchTerm = "";
                if (!$("#search").val() == "") {
                    searchTerm = $("#search").val();
                } else { // If it is empty, alert the user
                    alert("You must enter a search term!");
                }


                // Build the custom Twitter URL.
                var url = "http://api.twitter.com/1/statuses/user_timeline.json?" + searchTerm + "&count=5&include_rts=1&callback=?";


            $.getJSON(url, function(data) {     
                $.each(data, function(i,item) {
                    tweet += convertUrlToLink(item.text) + "<br><br>";

                    var datepublished = item.published.$t.substring(0, 19);  //Get the first 19 characters of date created.

                    // Construct the display for the video
                        var text =  
                            tweet += convertUrlToLink(item.text) + "<br><br>";                
                            "Published: " + datepublished + " by " + author + "<br><br>"; 
                            "<br><a href='" + url + "'>" + title + "</a><br>" +

                        // Append the text string to the div for display
                        $("#tweets").append(text);



                });
                    //Display the number of followers and friends for the user account.
                    html += "<p>Followers: " + followers_count + "</p><br>";
                    html += "<p>Friends: " + friends_count + "</p><br>";
                    //tweet += user.followers_count(item.text) + "<br><br>";
                    //tweet += user.friends_count(item.text) + "<br><br>"; 

            });     

            function convertUrlToLink(text) {
                var exp = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
                return text.replace(exp,"<br><a href='$1'>$1</a>");  
            }
        });
        });

What I am trying to do, This application will display the first five tweets for the twitter account that's entered in the Search Box. After the tweets, I want to display the number of followers and friends for the account being viewed. As of right now, it is not working. Can someone look at my code and see what is wrong with it? Thank you.

I don't use jQuery often, but as I understand it JSON-P is designed to wrap a JSON object in a callback function as part of the response. If you were to trace the ajax call (through the browser debugger), I bet you would see that you are getting something that looks like ?({"data":"content"}); where "?" is trying to be a function (which it clearly is not).

Maybe someone with more experience with jquery can chime in?

Thank ou

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.