javascript で www.example.com/example.php?d=a のような ajax get リクエストを作成するにはどうすればよいですか? 私はもう試した:
xmlhttp.open("GET","www.example.com/example.php?d=a",true);
xmlhttp.send();
誰かが私に実用的な例を提供できますか? ありがとう。
javascript で www.example.com/example.php?d=a のような ajax get リクエストを作成するにはどうすればよいですか? 私はもう試した:
xmlhttp.open("GET","www.example.com/example.php?d=a",true);
xmlhttp.send();
誰かが私に実用的な例を提供できますか? ありがとう。
本当に GET を使用したい場合は、次のコードを使用します。
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","the_page_to_send_request_to.someFileFormat",true);
xmlhttp.send();
もちろん :)
str
この関数は、任意のデータ ( ) を任意の場所 ( ) に送信する (POST) リクエストを作成しますphplocation
。xmlhttp.responseText
サーバーが送り返すものは何でもです:)
<script type="text/javascript">
function submitForm(str, phpLocation)
{
var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState<4)
{
//i'm not ready yet. Do stuff.....
}
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
//Now I'm ready. Do stuff with this: xmlhttp.responseText;
}
}
xmlhttp.open("POST", phpLocation, true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("str=" + encodeURIComponent(str));
}
</script>