Article From:https://segmentfault.com/q/1010000010075846
Question:

Document interpretation

The meaning of the document should beWhen converting a custom dataType option type to a known typeWhen you need to use the contents parameter

I wrote it as an example of the document, executing only the function defined by the “text mycustomtype” attribute, which does not perform the function defined by the “mycustomtype JSON” attribute, and the code is as follows

    $.ajax({
        url: 'Home/Index',
        type: 'post',
        dataType: 'mycustomtype',
        contents: {
            mycustomtype: /mycustomtype/
        },
        converters: {
            'text mycustomtype': true,
            'mycustomtype json': function () {
                console.log('converters')
            }
        }
    })

Is it a problem for me to understand? Is it an example of the document I didn’t understand?

Of course, the most important thing is the function of contents.

Answer 0:

It’s the same.
How do these three parameters use? What the rule is, is confused.

jQuery.ajaxSetup({
  accepts: {
    script: "text/javascript, application/javascript"
  },
  contents: {
    script: /javascript/
  },
  converters: {
    "text script": jQuery.globalEval
  }
});

Answer 1:
$.ajax({
        url: '/path/to/file',
        type: 'default GET (Other values: POST)',
        dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
        data: {param1: 'value1'},
    })
    .done(function() {
        console.log("success");
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });

contentsNo eggs are used.

Leave a Reply

Your email address will not be published. Required fields are marked *