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)

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...