微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – 我在一次考试中遇到ajax调用问题

我在考试中碰到了这个问题.有人可以帮忙吗.在我的研究中,我发现dataType类似于’json’或’xml’,而不是精确的mime类型.
另一方面接受使用文字对象来定义mime-types.(从 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:dataType:’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.因此,这里的答案是接受的.

第二部分:

> type不是MIME类型,它是一个字符串(源here)
> request.mimeType不是XmlHttpRequest的有效属性(来源here)

因此答案是request.getResponseHeader(“Content-Type”)==’application / bint'(来源here)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐