Pass接受header参数到jquery ajax [英] Pass accepts header parameter to jquery ajax

查看:217
本文介绍了Pass接受header参数到jquery ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Chrome控制台中检查以下代码时,它会向我显示一个Request标头接受:undefined

When I inspect the following code in Chrome Console it shows me a Request header Accept:undefined

jQuery.ajax({
        url: _this.attr('href'),
        accepts: "application/json; charset=utf-8",

    });
});

如何将接受类型设置为json。我不想设置自定义标头或使用 beforeSend

How do I set accept type as json. I don't want to set a custom header or use beforeSend

推荐答案

试试这个,

$.ajax({     
  headers: {          
    Accept: "text/plain; charset=utf-8",         
    "Content-Type": "text/plain; charset=utf-8"   
  }     
  data: "data",    
  success : function(response) {  
    // ...
  }
});

请参阅此帖子以供参考:

See this post for reference:

无法使用jQuery正确设置Accept HTTP标头

这篇关于Pass接受header参数到jquery ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆