首页 > 其他分享 >jquery ajax contentType为application/json及设置请求头header

jquery ajax contentType为application/json及设置请求头header

时间:2023-04-14 10:22:24浏览次数:37  
标签:jquery function contentType application ajax header json data

1.找了好久发现contentType一般为默认的application/x-www-form-urlencoded,这次post请求后台限定了为application/json

2.当设置contentType为application/json还是出错时,把data也要转换一下

$.ajax({
    method: "POST",
    url: "",
    contentType: 'application/json',
    data:JSON.stringify({
            "id": id
    }),
    success: function( data ) {
 
   }
});

jquery ajax 设置请求头header 参数

$.ajax(
                {
                    url:'http://127.0.0.1:30080/api-a/quasiCustom/selectCustomList',
                    type:'post',
                    dateType:'json',
                    beforeSend: function(xhr) {
                        xhr.setRequestHeader("organId:'1333333333'");
                    },
                    headers:{'Content-Type':'application/json;charset=utf8','organId':'1333333333'},
                    data:JSON.stringify(org),
                    success:function(data){console.log("sucess");},
                    error:function(data){console.log("error");}
                }
            );

  

 

标签:jquery,function,contentType,application,ajax,header,json,data
From: https://www.cnblogs.com/daboluo/p/17317492.html

相关文章

  • 前端_发起axios请求,前端无法获取response的全部header
    问题描述使用vueaxios向python+flask搭建的服务端发起请求,请求成功后,前端无法拿到服务端添加到header中的token。问题原因前后端分离,默认reponseheader只能取到以下信息Content-LanguageContent-TypeExpiresLast-ModifiedPragma解决方法要获取其他的headers信息......
  • jQueryUI教程_编程入门自学教程_菜鸟教程-免费教程分享
    教程简介JqueryUI入门教程-从基本到高级概念的简单简单步骤了解JqueryUI,其中包括概述,环境设置,交互,可拖动,可放置,可调整大小,可选,可排序,小部件,手风琴,自动完成,按钮,Datepicker,对话框,菜单,Progressbar,Slider,Spinner,Tabs,Tooltip,Effects,AddClass,ColorAnimation,Effect,Hide,RemoveClass......
  • ubuntu 编译出现错误fatal error: bits/libc-header-start.h: No such file or direct
    在ubuntugcc编译程序出现错误fatalerror:bits/libc-header-start.h:Nosuchfileordirectory表明缺少库环境。解决方法aptupdateapt-getinstallgcc-multilib成功编译......
  • SpringMVC中使用引入jquery不能加载页面
    今天在学习springMVC的json数据绑定时,需要使用到jquery发送ajax请求。但是当我通过是<script>标签引入了jquery.js。但是当我访问该jsp的时候就是不显示页面的内容我一直以为时SpringMVC的servelt拦截器拦截了静态资源,但是我过滤了静态资源还是不显示。后来才发现,我把<script......
  • 爬虫最后一天,爬取到的数据存到mysql中,爬虫和下载中间件、加代理、cookie、header、se
    爬到的数据存到mysql中classFirstscrapyMySqlPipeline:defopen_spider(self,spider):print('我开了')self.conn=pymysql.connect(user='root',password="",host='127.0.0.1......
  • jQuery代码实现购物车效果
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=d......
  • 2023.04.07 - 用jQuery发起JSONP请求时jsonpCallback和success的回调区别在哪?
    在使用jQuery发起跨域请求时,可以通过指定dataType为jsonp来实现JSONP跨域请求。此时,jQuery会自动生成一个回调函数,并将其作为参数发送给服务器。服务器需要将返回数据包装在回调函数中,以便于客户端解析。以下是一个简单的jQuery实现JSONP跨域请求的示例:$.ajax({......
  • RecyclerView:带header的grid
    RecyclerView是一个高度可定制性的View本文将使用RecyclerView实现带header的grid为了用RecyclerView创建一个带header的grid:1,定义一个具有两种view类型的adapter,一个为header,一个为普通item。2,nflate一个header,把它传递给adapter。3,重写GridLayout......
  • jquery 根据开始日期加天数计算有效期
    functiondateTime(startDate,dayTime){//起始日期,天数  vardate=newDate(startDate);  varnewDate=newDate(date.getFullYear(),date.getMonth(),date.getDate()+dayTime);  varyear1=date.getFullYear();  varmonth1=date.getMonth()+1;  var......
  • jquery触发/失去焦点事件
    触发焦点:$("Element").focus()触发每一个匹配元素获得焦点事件。$("Element").focus(function)事件会在获得焦点的时候触发,既可以是鼠标行为,也可以是按tab键导航触发的行为,并且绑定一个处理方法。失去焦点:$("Element").blur()触发每一个匹配元素失去焦点事件。$("Element"......