jQuery - AJAX get() 和 post() 方法

我就是我 2021-10-19 01:26 471阅读 0赞
  • GET - 从指定的资源请求数据
  • POST - 向指定的资源提交要处理的数据

GET

必需的 URL 参数规定您希望请求的 URL。

可选的 callback 参数是请求成功后所执行的函数名。

下面的例子使用 $.get() 方法从服务器上的一个文件中取回数据:

  1. $("button").click(function(){
  2. $.get("demo_test.asp",function(data,status){
  3. alert("Data: " + data + "\nStatus: " + status);
  4. });
  5. });

POST

必需的 URL 参数规定您希望请求的 URL。

可选的 data 参数规定连同请求发送的数据。

可选的 callback 参数是请求成功后所执行的函数名。

  1. $("button").click(function(){
  2. $.post("demo_test_post.asp",
  3. {
  4. name:"Donald Duck",
  5. city:"Duckburg"
  6. },
  7. function(data,status){
  8. alert("Data: " + data + "\nStatus: " + status);
  9. });
  10. });

2019081410531027.png

ASP文件:

  1. <%
  2. dim fname,city
  3. fname=Request.Form("name")
  4. city=Request.Form("city")
  5. Response.Write("Dear " & fname & ". ")
  6. Response.Write("Hope you live well in " & city & ".")
  7. %>

发表评论

表情:
评论列表 (有 0 条评论,471人围观)

还没有评论,来说两句吧...

相关阅读