前端ajax传参字符串拼接 以及data传参

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
   <button style="width: 100px;height: 100px" οnclick="typecontent('文件','删除')">点击跳转</button>

<button style="width: 100px;height: 100px" οnclick="typecon ('文件')">点击</button>



   <form id='addForm' action='UserAdd.action' type='post'>
       <label for='uname'>用户名</label>:<input type='text' name='uname' id='uname'><br>

       <label for='mobileIpt'>手机号:</label><input type='text' name='mobileIpt' id='mobileIpt'><br>

       <label for='birthday'>生日:</label><input type='text' name='birthday'><br>
       
       <input type='button' value='提交' οnclick='addUser()'>
   </form>



</body>
</html>

<script src="https://code.jquery.com/jquery-3.3.1.min.js "></script>
<script>

   function typecon(id) {
       window.location.href = "https://www.jd.com?id=" + id ;
   }

    function typecontent(id,admin) {
        window.location.href = "https://www.baidu.com/?id=" + id+"&admin="+admin;
    }

   $.ajax({
       type: 'post',
       url: 'aaa/bbb.do',
       contentType: 'application/json;charset=utf-8',
       data: '{"name": "uname", "age": 18}',
       success: function (data) { //返回json结果
           alert(data);
       }
   });


   function addUser(){
       var user = {
           uname:$("#uname").val(),
           mobileIpt:$("#mobileIpt").val(),
           birthday:$("#birthday").val()
       };
       $.ajax({
           url:'UserAdd.action',
           data:user,
           type:'post',
           dataType:'text',
           success:function(msg){
               if(msg=='1'){
                   console.log('添加成功');
               }else{
                   console.log('添加失败')
               }
           }

       })
   }

</script>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值