jquery ajax contenttype datatype,javascript - Differences between contentType and dataType in jQuery...

I have the following Jquery callback function and I have a litle doubt about it (I don't know very well Jquery):

$("form.readXmlForm").submit(function() {

// Riferimento all'elemento form che ha scatenato il submit

var form = $(this);

// Variabile che contiene il riferimento al bottone clickato

var button = form.children(":first");

$.ajax({ // Viene eseguita la chiamata AJAX

type: "POST", // Tipo di richiesta: POST

// URL verso quale viene inviata la richiesta

url: form.attr("action"),

// Dati XML inviati:

data: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>barapple",

// Tipo di media type accettabile dalla response:

contentType: "application/xml",

dataType: "text",

success: function(text) {

MvcUtil.showSuccessResponse(text, button);

},

error: function(xhr) {

MvcUtil.showErrorResponse(xhr.responseText, button);

}

});

As you can see this function simply execute an AJAX Request to the backend setting the parameter for this request.

I have set that I am sending the request towards an URL, that the request is a POST request and that the data that I am sending are the following string:

"barapple"

I have some difficulties to understand what is the differences between contentType and dataType

I think that contentType specify the type of data that are acceptable recived in the HTTP Response, is it right?

And dataType? What say? The type of data that I am sending in the HTTP Request?

In this case is is "text" because I am sending a textual string that rappresent XML code?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值