首页 前端知识 jquery ajax post 请求表单格式x-www-form-urlencoded

jquery ajax post 请求表单格式x-www-form-urlencoded

2024-09-03 02:09:28 前端知识 前端哥 306 291 我要收藏

<body>
    <form id="submitForm">
      <input type="hidden" id="userId" name="userId" value="283" />
      <input type="hidden" id="pageSize" name="pageSize" value="99" />
    </form>
    <div class="wrap">
        666        
    </div>
</body>
<script src="js/jquery-1.12.4.min.js"></script>
<script>
  const serialize = (formEle) => Array.from(new FormData(formEle)).reduce((p, [k, v]) => Object.assign({}, p, { [k]: p[k] ? (Array.isArray(p[k]) ? p[k] : [p[k]]).concat(v) : v }), {});
  const jsonData = serialize($("#submitForm").get(0));
  $.ajax({
    url: 'https://tool.keeko.ai/prod-api/api/school/getCourseTrainingList',
    type: 'POST',
    data: jsonData,
    contentType: 'application/x-www-form-urlencoded',
    success: function(response) {
        // 请求成功时的处理逻辑
    },
    error: function(xhr, status, error) {
        // 请求失败时的处理逻辑
    }
  });  
</script>

转载请注明出处或者链接地址:https://www.qianduange.cn//article/17592.html
标签
评论
发布的文章

关于HTML的知识

2024-09-18 23:09:36

js简单实现轮播图效果

2024-09-18 23:09:36

CSS3美化网页元素

2024-09-18 23:09:27

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!