Camarellini Viberg
Camarellini Viberg

Reputation: 303

What is the benefit of manually specifying the MIME type when sending an AJAX request?

The jQuery library has a built in function called .overrideMimeType(). Why is this a beneficial thing to do? What kind of issues may arise if I don't do this? It seems to crop up quite frequently, but I can't find a good explanation via Google.

Thank you for your help.

Upvotes: 0

Views: 45

Answers (1)

Quentin
Quentin

Reputation: 944564

It hacks around web services which lie about what sort of content they are serving.

Most commonly, this involves PHP scripts since PHP defaults to claiming Content-Type: text/html and many PHP authors don't know they should header("Content-Type: application/json"); before they echo json_encode($some_data);.

Upvotes: 2

Related Questions