私のAJAX呼び出しが何を返すのではなく、どちらか失敗していません

StackOverflow https://stackoverflow.com/questions/2299754

質問

私はこのHTMLを持っています:

<input type="text" id="text"/>
<input type="button" id="submit" value="Submit" />
<div id="twitter_update_list">
</div>

このジャバスクリプトます:

var xmlHttp;
document.body.onclick = function(){
    var username = document.getElementById('text').value;
    selectUser(username);
}
    function selectUser(username){
        var url = "http://twitter.com/statuses/user_timeline/" + username + ".json?callback=twitterCallback2&count=100";
        try{// Opera 8.0+, Firefox, Safari
            xmlHttp = new XMLHttpRequest();
        }catch (e){// IE
            try{
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    // Something went wrong
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        xmlHttp.onreadystatechange = processRequest;
        xmlHttp.open( "GET", url, true );
        xmlHttp.send( null );
    }

    function processRequest(){
        if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
            if ( xmlHttp.responseText == "Not found" ) {
                document.getElementById('twitter_update_list').innerHtml = "Not found";
            }else if(xmlHttp.responseText == " "){
                document.getElementById('twitter_update_list').value = "Empty";
            }else{
                // No parsing necessary with JSON!        
                document.getElementById('twitter_update_list').value = xmlHttp.responseText;
                console.log(xmlHttp.responseText);
            }
        }
    }

私は放火犯を見ていると私はverything参照正しく送信されますが、私は一切応答を得ることはありません。私はそれを練習したいので、ああ、私は生のjavascriptを使用してい。 =)

役に立ちましたか?

解決

あなたは、クロスドメインのXMLHttpRequestをやろうとしています。サービスはJSONPをサポートすることができるが、それは動作しません。 JSOP要求を行うには、次のいずれかが必要正しいイベントハンドラで<script>タグを注入したり、そのようなjQueryのようなフレームワークを使用します。

他のヒント

あなたはjqueryのを使用する場合は、単純にこれを行うことができます。

$.load("http://twitter.com/statuses/user_timeline/"+username,
function(data)
{
alert(data);
}
);
指定されたユーザー名

のためusertimelineを表示します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top