[Solved] jquery ajax isn’t working


First your URL is not correct. Instead of

user_id=id

in your URL you have to use a actual value for id (id is just placeholder in your case). For example:

user_id=82193320

which would give you the data for my twitter user (uwe_guenther) back.

You can easily lookup twitter ids here:

http://mytwitterid.com/

If you just want to lookup user data by screen name you could use:

screen_name=uwe_guenther

instead.

The Twitter API description can you find here:

https://dev.twitter.com/docs/api/1/get/users/show

I have attached a working example for looking up screen_name by user_id and user_id by screen_name here:

The jsFiddle with the following example can be found here: http://jsfiddle.net/uwe_guenther/EvJBu/

index.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <input id='userIdTextField' type="text" placeholder="user_id"/>
    <input id='userIdSubmitButton' type="submit" value="Submit"/>
    <div id='screenNameResultView'></div>
    <br>
    <input id='screenNameTextField' type="text" placeholder="screen_name"/>
    <input id='screenNameSubmitButton' type="submit" value="Submit"/>
    <div id='userIdResultView'></div>
    <br>

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="main.js"></script>
</body>
</html>

main.js

$(document).ready(function (){

    $('#userIdSubmitButton').click(function (){
        var userId = $('#userIdTextField').val();
        $.ajax({
            type: "GET",
            url: "http://api.twitter.com/1/users/show.json?user_id=" + userId + "&include_entities=true&callback=?",
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            cache:true,
            timeout:1000,
            success: function (json) {
                alert("Successfull: screen_name=" + json.screen_name);
                $('#screenNameResultView').text("screen_name=" + json.screen_name);
                console.log(json);
            },
            error: function () {
                alert("No Result");
            }
        });
    });

    $('#screenNameSubmitButton').click(function (){
        var screenName = $('#screenNameTextField').val();
        $.ajax({
            type: "GET",
            url: "http://api.twitter.com/1/users/show.json?screen_name=" + screenName + "&include_entities=true&callback=?",
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            cache:true,
            timeout:1000,
            success: function (json) {
                alert("Successfull: user_id=" + json.id);
                $('#userIdResultView').text("user_id=" + json.id);
                console.log(json);
            },
            error: function () {
                alert("No Result");
            }
        });
    });
});



solved jquery ajax isn’t working