我有以下 Jquery 回调函数,我对此有点怀疑(我不太了解 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\"?><javaBean><foo>bar</foo><fruit>apple</fruit></javaBean>",
// 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);
}
});
如您所见,此函数只需执行一个 AJAX 请求到后端设置此请求的参数。
我已经设置我向 URL 发送请求,请求是一个 POST 请求,我发送的数据是以下字符串:
“苹果”
我在理解contentType和dataType之间有什么区别时遇到了一些困难
我认为contentType指定了 HTTP 响应中可接受的数据类型,对吗?
和数据类型?说啥?我在 HTTP 请求中发送的数据类型?
在这种情况下是“文本”,因为我正在发送一个文本字符串,它代表 XML 代码?