我在考试时遇到了这个问题。有人可以帮忙吗?在我的研究中,我发现 dataType 类似于“json”或“xml”,而不是确切的 mime 类型。 另一方面接受使用文字对象来定义 mime 类型。(根据 this 判断)。类似于:
$.ajax({
url: ...
dataType: 'json',
accepts: {
xml: 'text/xml',
text: 'text/plain'
}
});
内容类型适用于
When sending data to the server, use this content type.
来自 jQuery 文档。
如果有人能帮助解决这个问题那就太好了。谢谢。
考试问题:
You are developing a web application that retrieves data from a web service. The data being retrieved is a custom binary datatype named bint. The data can also be represented in XML. Two existing methods named parseXml() and parseBint() are defined on the page.
The application must: ? Retrieve and parse data from the web service by using binary format if possible ? Retrieve and parse the data from the web service by using XML when binary format is not possible
You need to develop the application to meet the requirements. What should you do? (To answer, drag the appropriate code segment to the correct location. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
代码:
var request = $.ajax({
uri: '/',
选项 1:接受:'application/bint,text/xml',
选项 2:contentType:'application/bint,text/xml'
选项 3:数据类型:'application/bint,text/xml'
dataFilter: function(data, type) {
选项 1:if(request.getResponseHeader("Content-Type"== 'application/bint')
选项 2:if(type == 'application/bint')
选项 3:if(request.mimeType == 'application/bint')
},
success: function(data) {
start(data);
}
});
最佳答案
我认为这里的关键是这一点:
The data being retrieved is a custom binary datatype named bint.
这意味着您期待 bint
,而不是发送 bint
。因此,这里的答案是接受
。
第二部分:
因此答案是 request.getResponseHeader("Content-Type") == 'application/bint'
(来源 here )
关于jquery - 我在一项考试中遇到 ajax 调用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29103455/