Difference between contenttype and datatype in Ajax request of jquery

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: