Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have issue with ajax call on one exam

Tags:

json

jquery

ajax

I bumped into this question on exam. Can someone help with it. In my research I found that dataType is something like 'json' or 'xml' not the exact mime-type. Accepts in other hand use literal object to define mime-types.(judging by this). Something like:

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

And content type is for

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

from jQuery documentation.

If someone can help with this question will be great. Thanks.

Exam Question:

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.)

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);
    }
});
like image 836
Georgi Filipov Avatar asked Sep 29 '22 12:09

Georgi Filipov


1 Answers

I think the key here is this bit:

The data being retrieved is a custom binary datatype named bint.

This means that you're expecting bint, not sending bint. Therefore, the answer here is accepts.

For the second part:

  1. type is not a MIME type, it's a string (source here)
  2. request.mimeType is not a valid property of XmlHttpRequest (source here)

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

like image 116
Maria Ines Parnisari Avatar answered Nov 15 '22 10:11

Maria Ines Parnisari