通过Ajax发送请求

从后台返回数据:

通过Ajax去拿到后台返回前台的数据

 

第一种方式:$.get("demo_test.php",function(data,status){

 alert("数据: " + data +"\n状态: " + status);

});

用get请求里面只有两个参数,一个是地址,一个是回调函数,里面可以不用传递数据

 

第二种方式:

$.post("/try/ajax/demo_test_post.php",

    {name:"菜鸟教程",url:"http://www.runoob.com"},

    function(data,status){

        alert("数据: \n" + data+ "\n状态: " + status);

    });

 

Post方式里面有三个参数  第一个是访问的地址,第二个是携带的数据,第三个是回调函数

第三种方式:

$.ajax({

   type: "POST",

   url: "some.php",

  async: false

   data:"name=John&location=Boston",

   success: function(msg){

     alert( "Data Saved:" + msg );

   }

});

这里有四个参数,里面也可以继续添加参数。

如果直接访问servlet ,则可以通过以下方式访问



猜你喜欢

转载自blog.csdn.net/csdn19970806/article/details/80382470