I have a problem with ajax call in one exam

I came across this question in an exam. Can someone help with this. In my research, I found that dataType is something like "json" or "xml", and not the exact type of mime. Accepts in another manual use a literal object for defining mime types (judging by this ). Sort of:

$.ajax({ url: ... dataType: 'json', accepts: { xml: 'text/xml', text: 'text/plain' } }); 

And the type of content for

When sending data to the server, use this type of content.

from jQuery documentation.

If anyone can help with this, this will be great. Thanks.

Exam Question:

You are developing a web application that extracts data from the Internet providing services. The received data is its own binary data type with the name bandage. Data can also be represented in XML. The two existing methods named parseXml () and parseBint () are defined on the page.

The application should :? Getting and analyzing data from a web service using a binary format, if possible? Extract and parse data from a web service using XML when a binary format is not possible

You need to develop an application to meet the requirements. What should you do? (To answer, drag the corresponding code segment to the correct location. Each code segment can be used once, more than once, or not at all. You may need to drag the separation bar between the panels or scroll to view the contents.)

the code:

 var request = $.ajax({ uri: '/', 

option 1: accepts: 'application/bint, text/xml',

option 2: contentType: 'application/bint, text/xml'

option 3: dataType: 'application/bint, text/xml'

  dataFilter: function(data, type) { 

option 1: if(request.getResponseHeader("Content-Type" == 'application/bint')

option 2: if(type == 'application/bint')

option 3: if(request.mimeType == 'application/bint')

  }, success: function(data) { start(data); } }); 
+5
source share
2 answers

I think the key here is a bit:

The resulting data is its own binary data type called bint.

This means that you expect bint without sending bint . So the answer here is accepts .

For the second part:

  • type not a MIME type, it is a string (source here )
  • request.mimeType not a valid XmlHttpRequest property (source here )

So the response is request.getResponseHeader("Content-Type") == 'application/bint' (source here )

+2
source

Option 1: accepts: 'application/bint, text/xml' because it expected a type of bint or xml

Option 2: if(type == 'application/bint')

he is lower

 dataType: xpto, dataFilter: function(data, type){ alert(type); //xpto } 
-1
source

Source: https://habr.com/ru/post/1215542/


All Articles