The difference between contentType and dataType in jQuery AJAX requests
DataType: The type of data that you want the back end server to send to the front end. If this property is not set, what data type the server returns is a string in the appropriate type format.
//Use jQuery to write an AJAX request
function getMsg(data) {
$.ajax({
url:'/mobian/test1.action',
type:'POST',
contentType: 'application/json; charset=UTF-8', //The data sent from the front end to the backend server is in JSON format.
async:false,
dataType:'json', //The front end expects to receive data in JSON format.
data:JSON.stringify(data), //We have specified JSON format, so we need to make the data data into JSON format.
success: function (response) {
console.log(response);
}
})
}
Read More:
- If the request parameter is formdata, use the Ajax operation
- [Solved] it only responds to error and does not enter success after AJAX is successfully processed
- The solution of calling$. Ajax successfully but the success method does not respond
- Summary of jQuery autocomplete plug-in
- [Solved] ajax Error: Uncaught SyntaxError: Unexpected end of JSON input
- The solution that needs alert to execute after using ajax
- Uncaught Error: Unrecognized datatype for attribute “news.news_date“
- Interface request error 504 gateway time out [How to Solve]
- How to download files by post submission under Ajax
- [Solved] JQuery each Method Error: $XXX is not defined
- The reason why jQuery files report errors is introduced
- Solve the asynchronous execution of callback function in Axios request processing interceptor
- Trigger http request when tab page is closed in angular2+ project
- Difference between innerHTML and innerText
- [Solved] node.js request Error: Error: unable to verify the first certificate
- [Solved] Font End Image Display Error: net::ERR_CONNECTION_RESET 431 (Request Header Fields Too Large)
- request.js?b775:101 Uncaught (in promise) Error: Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Long’;
- JS getting ${pageContext.request.contextPath} Get the root path of the project
- proxy error: could not proxy request [How to Solve]