How To Make Post Use ContentType Application Json In Jquery
Maybe your like
- Home
- Community
- Categories
- Web Development
- JQuery
- How to make post use contentType application...
How can I make $.post() send contentType=application/json? I already have a large number of $.post() functions, so I don't want to change to $.ajax() because it would take too much time
If I try
$.post(url, data, function(), "json")It still has contentType=application/x-www-form-urlencoded. So what exactly does the "json" param do if it does not change the contenttype to json?
If I try
$.ajaxSetup({ contentType: "application/json; charset=utf-8" });That works but affects every single $.get and $.post that I have and causes some to break.
So is there some way that I can change the behavior of $.post() to send contentType=application/json?
- html
- laravel
- javascript
- angular
- jquery
- php
Nov 24, 2020 in JQuery by kartik • 37,520 points • 13,387 views answer comment - flag
Your comment on this question:
| Your name to display (optional): |
| Email me at this address if a comment is added after mine: |
| Privacy: Your email address will only be used for sending these notifications. |
| Add comment Cancel |
1 answer to this question.
Your answer
| Your name to display (optional): |
| Email me at this address if my answer is selected or commented on: |
| Privacy: Your email address will only be used for sending these notifications. |
| Add answer Cancel |
Hii,
Try this:
$.ajax({ url:url, type:"POST", data:data, contentType:"application/json; charset=utf-8", dataType:"json", success: function(){ ... } })- flag
- ask related question
Your comment on this answer:
| Your name to display (optional): |
| Email me at this address if a comment is added after mine: |
| Privacy: Your email address will only be used for sending these notifications. |
| Add comment Cancel |
Related Questions In JQuery
0 votes 1 answerHow to call $(window).on("load", function) in jQuery-3.3.1?
Use $(document).ready() instead of $(window).on("load", function... $(document).ready(function() { ...READ MORE
answered Jun 21, 2022 in JQuery by rajatha • 7,680 points • 4,313 views- javascriptjqueryonload
How to set cache false for getJSON in jQuery?
Hello @kartik, Your code just needs a trigger ...READ MORE
answered May 12, 2020 in JQuery by Niroj • 82,800 points • 1,613 views- html
- cass
- javascript
- laravel
- php
- jquery
How to set cache false for getJSON in jQuery?
You can't pass any configuration parameters to ...READ MORE
answered Oct 7, 2020 in JQuery by Amit • 140 points • 3,875 views- html
- laravel
- php
- jquery
- javascript
- css
How to check if button is disabled in jQuery Mobile?
Hello, you can try $("#deliveryNext").is(":disabled") The following code works for ...READ MORE
answered May 29, 2020 in JQuery by Niroj • 82,800 points • 5,689 views- html
- css
- javascript
- laravel
- php
How to set jquery input select all on focus?
Hello @kartik, Try using click instead of focus. It seems to ...READ MORE
answered Nov 24, 2020 in JQuery by Niroj • 82,800 points • 5,245 views- html
- laravel
- javascript
- angular
- jquery
- php
How to add a “readonly” attribute to an <input>?
Hello, For jQuery <1.9 $('#inputId').attr('readonly', true); ...READ MORE
answered Nov 24, 2020 in JQuery by Niroj • 82,800 points • 2,415 views- html
- laravel
- javascript
- angular
- jquery
- php
How to set radio option checked onload with jQuery?
Hii, Say you had radio buttons like these, ...READ MORE
answered Nov 24, 2020 in JQuery by Niroj • 82,800 points • 7,360 views- html
- laravel
- javascript
- angular
- jquery
- php
How to find the version of an installed node.js/npm package?
Hello, npm view <package> version - returns the latest ...READ MORE
answered Nov 24, 2020 in Node-js by Niroj • 82,800 points • 8,023 views- html
- laravel
- javascript
- angular
- jquery
- php
How to use $(document).ready equivalent without jQuery
Hello @kartik, Using DOMContentLoaded that is supported by over ...READ MORE
answered Sep 10, 2020 in JQuery by Niroj • 82,800 points • 2,256 views- html
- css
- javascript
- laravel
- php
How to pass parameters in GET requests with jQuery?
Hello, Here is the syntax using jQuery $.get $.get(url, data, ...READ MORE
answered Apr 28, 2020 in JQuery by Niroj • 82,800 points • 45,746 views- html
- css
- javascript
- angular
- laravel
- php
Recent in JQuery
- How to implement dynamic content loading in jQuery Accordion Widget panels? Apr 3
- What is the difference between navigate and navigate by URL? Mar 11
- Does ListView inherently support lazy loading? Feb 10
- Horizontal scrolling and vertical scrolling in JqueryMobile Jun 21, 2022
- Jquery - Using .each() with variables and an IF statement Jun 21, 2022
- All categories
-
Generative AI (1,454) -
Power BI (1,316) -
DevOps & Agile (4,138) -
Data Science (100) -
ChatGPT (30) -
Cyber Security & Ethical Hacking (1,057) -
Data Analytics (1,266) -
Cloud Computing (4,053) -
Machine Learning (337) -
PMP (1,069) -
Python (3,489) -
SalesForce (201) -
Selenium (1,624) -
Software Testing (58) -
Tableau (608) -
Web Development (3,972) -
UI UX Design (24) -
Java (1,358) -
Azure (157) -
Database (858) -
Big Data Hadoop (1,907) -
Blockchain (1,673) -
Digital Marketing (121) -
C# (141) -
C++ (272) -
IoT (Internet of Things) (390) -
Kotlin (8) -
Linux Administration (389) -
MicroStrategy (7) -
Mobile Development (395) -
Others (2,387) -
RPA (653) -
Talend (73) -
TypeSript (124) -
Apache Kafka (84) -
Apache Spark (596) -
Career Counselling (1,091) -
Events & Trending Topics (28) -
Ask us Anything! (71)
Join the world's most active Tech Community!
Welcome back to the World's most active Tech Community!
Sign up with Gmail Sign up with FacebookOR
Password must haveAt least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
SIGN UP Already have an Edureka Account? Login Forgot Password? LOGIN Don’t have edureka account? Sign Up resend ? Password must haveAt least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
reset password Don’t have edureka account? Sign Up reset password Don’t have edureka account? Sign Up Send Code Don’t have edureka account? Sign UpSubscribe to our Newsletter, and get personalized recommendations.
Already have an account? Sign in.
Tag » Add Content Type In Ajax Call
-
Cannot Set Content-type To 'application/json' In JQuery.ajax
-
Jquery Ajax Set Content-type Code Example
-
Content-type Application/json Ajax Code Example
-
JQuery Ajax Contenttype | Learn The Working Of Ajax Contenttype Option
-
JQuery.ajax() | JQuery API Documentation
-
Ajax With ContentType: 'application/json' - JQuery Forum
-
JQuery Ajax() Method - TutorialsTeacher
-
JQuery AJAX POST Tutorial - AirPair
-
What Is Content-type And Datatype In An AJAX Request?
-
Cannot Set Content-type To 'application/json' In JQuery.ajax - ITecNote
-
Ajax And Form ContentType & & DataType - Develop Paper
-
JQuery Ajax() Method - W3Schools
-
Not Able To Get JSON Parameter In Controller With Content-type Json ...
-
Utiliser Fetch - Référence Web API | MDN
Generative AI
Power BI
DevOps & Agile
Cyber Security & Ethical Hacking
Data Analytics
Cloud Computing
Machine Learning
Python
Selenium
Software Testing
Tableau
Web Development
Java
Database
Big Data Hadoop
Blockchain
IoT (Internet of Things)
Linux Administration
MicroStrategy
RPA
Talend
Apache Kafka
Apache Spark
Career Counselling
Events & Trending Topics