0%

Http Get and Post Request in Javascript

使用Javascript发送Get/Post请求的方法。

发送Get请求

1
2
3
4
5
6
7
function httpGet(url)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", url, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}

发送POST请求

1
2
3
4
5
6
7
function httpPost(url)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", url, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}