zl程序教程

您现在的位置是:首页 >  前端

当前栏目

怎样通过ajax提交数据

AJAX数据 通过 怎样 提交
2023-09-27 14:27:41 时间

ajax的出现彻底改变了javascript命运,通过ajax可以直接向服务器提交数据,有两种方式:

get方式,数据直接拼接在地址中
post方式,数据由data字段携带

post方式,data中是参数。

    $.ajax({
        url:"http://localhost/contact2/user/list.do",
        type:"post",
        dataType:"json",
        data:"username=王&order=desc",
        success:function(data){
            alert("11");
        }

    });

get方式,数据在地址栏中:

    $.ajax({
        url:"http://localhost/contact2/user/list.do?username=zhangsan",
        type:"post",
        dataType:"json",
        success:function(data){
            alert("11");
        }

    });