$.get() 方法通过 HTTP GET 请求从服务器上请求数据。
语法:
$.get(URL,callback)
必需的 URL 参数规定您希望请求的 URL。
可选的 callback 参数是请求成功后所执行的函数名。
例子:
<script>
$(document).ready(function(){
$("button").click(function(){
$.get("/try/ajax/demo_test.php",function(data,status){
alert("数据: " + data + "\n状态: " + status)
})
})
})
</script>
希望对你有帮助,望采纳!
请参照下面的例子:
/*URL可以随意改*/
String uriAPI = "http://192.168.1.100:8080/test/test.jsp?u=wangyi&p=456"
/*建立HTTP Get对象*/
HttpGet httpRequest = new HttpGet(uriAPI)
try
{
/*发送请求并等待响应*/
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest)
/*若状态码为200 ok*/
if(httpResponse.getStatusLine().getStatusCode() == 200)
{
/*读*/
String strResult = EntityUtils.toString(httpResponse.getEntity())
/*去没有用的字符*/
strResult = eregi_replace("(\r\n|\r|\n|\n\r)","",strResult)
mTextView1.setText(strResult)
}
else
{
mTextView1.setText("Error Response: "+httpResponse.getStatusLine().toString())
}
}
catch (ClientProtocolException e)
{
mTextView1.setText(e.getMessage().toString())
e.printStackTrace()
}
catch (IOException e)
{
mTextView1.setText(e.getMessage().toString())
e.printStackTrace()
}
catch (Exception e)
{
mTextView1.setText(e.getMessage().toString())
e.printStackTrace()
}
HTTP请求是指从客户端到服务器端的请求消息,包括消息首行中,对资源的请求方法、资源的标识符及使用的协议。如果HTTP/1.0服务器收到简单请求,它必须回应一个HTTP/0.9格式的简单回应。
get请求是以链接的方式,在链接的后方加上?就可以添加地址参数,并且可以添加多个。具体格式如下:
www.baidu.com?type=1&name=zhidao&value=10
在这个实例中可以看到,有三个参数,包括type、name、value,多个参数中间记得要用&符号隔开。
不知道你用的get是不是用的jQuery的$.get方法,jQuery的get方法链接是有长度限制的,具体的一下子也说不清楚,还是要靠你自己去学习。