JavaScript/JSのAJAXのリクエストを取得:
<script type = "text/javascript">/* xmlhttprequestオブジェクトを作成*/var xmlhttp;関数getXmlhttpobject(){if(window.xmlhttprequest){// ie7+、firefox、chrome、operaのコード、safari xmlhttp = new xmlhttprequest(); } else {// ie6のコード、ie5 xmlhttp = new ActiveXObject( "microsoft.xmlhttp"); } xmlhttpを返します。 } // --------------------- //関数getLabelsget(){xmlhttp = getXmlhttpobject(); if(xmlhttp == null){alert( 'ブラウザはajax!');戻る; } var id = document.getElementById( 'id')。value; var url = "http://www.leefrom.com?id="+id+"&"+math.random(); xmlhttp.open( "get"、url、true); xmlhttp.onreadystatechange = faveok; //イベントを送信した後、メッセージが受信されました。コール関数xmlhttp.send(); } function getokget(){if(xmlhttp.readystate == 1 || xmlhttp.readystate == 2 || xmlhttp.readystate == 3){//ローカルプロンプト:ロード} if(xmlhttp.readystate == 4 && xmlhttp.status == 200){ xmlhttp.responsetext; //処理結果は結果を返します}} </script>JavaScript/JSのAJAXのリクエストを投稿してください:
<script type = "text/javascript">/* xmlhttprequestオブジェクトを作成*/var xmlhttp;関数getXmlhttpobject(){if(window.xmlhttprequest){// ie7+、firefox、chrome、operaのコード、safari xmlhttp = new xmlhttprequest(); } else {// ie6のコード、ie5 xmlhttp = new ActiveXObject( "microsoft.xmlhttp"); } xmlhttpを返します。 } // --------------------- //関数getLabelspost(){xmlhttp = getXmlhttpobject(); if(xmlhttp == null){alert( 'ブラウザはajax!');戻る; } var url = "http://www.lifefrom.com/t/"+math.random(); xmlhttp.open( "post"、url、true); xmlhttp.setRequestheader( "content-type"、 "application/x-www-form-urlencoded"); xmlhttp.send(); xmlhttp.onreadystatechange = getLabelsok; //イベントを送信した後、メッセージが受信された後、関数を呼び出します}関数getokpost(){if(xmlhttp.readystate == 1 || xmlhttp.readystate == 2 || xmlhttp.endystate == 3){// (xmlhttp.readystate == 4 && xmlhttp.status == 200){var d = xmlhttp.responsetext; //戻り値//返品値の処理}} </script>注: XMLHTTPREQUESTはAJAXの基礎です。 xmlhttprequestオブジェクトを作成する場合、作成したajaxメソッドと同じ「<script> </script>」タグに属している必要があります。それ以外の場合、AJAX要求はエラーが発生し、データは返されません。 JavaScript/JS Ajax Post/Get Request。
JSネイティブAjax、Get and Postの上記の簡単な議論は、私があなたと共有するすべてのコンテンツです。参照を提供できることを願っています。wulin.comをもっとサポートできることを願っています。