Ajax call with contentType: ‘application/json’ not working

When using contentType: ‘application/json’ you will not be able to rely on $_POST being populated. $_POST is only populated for form-encoded content types. As such, you need to read your data from PHP raw input like this: $input = file_get_contents(‘php://input’); $object = json_decode($input); Of course if you want to send application/json you should actually send … Read more

Which JSON content type do I use?

For JSON text: application/json The MIME media type for JSON text is application/json. The default encoding is UTF-8. (Source: RFC 4627) For JSONP (runnable JavaScript) with callback: application/javascript Here are some blog posts that were mentioned in the relevant comments: Why you shouldn’t use text/html for JSON Internet Explorer sometimes has issues with application/json A rather … Read more

Set Content-type of media files stored on Blob

This should work: var storageAccount = CloudStorageAccount.Parse(“YOURCONNECTIONSTRING”); var blobClient = storageAccount.CreateCloudBlobClient(); var blobs = blobClient .GetContainerReference(“thecontainer”) .ListBlobs(useFlatBlobListing: true) .OfType<CloudBlockBlob>(); foreach (var blob in blobs) { if (Path.GetExtension(blob.Uri.AbsoluteUri) == “.mp4”) { blob.Properties.ContentType = “video/mp4”; } // repeat ad nauseam blob.SetProperties(); } Or set up a dictionary so you don’t have to write a bunch of if … Read more

Jquery ignores encoding ISO-8859-1

Because I had the same problem, I’ll provide a solution that worked for me. Background: Microsoft Excel is too stupid to export a CSV-File in charset UTF-8: $.ajax({ url: ‘…’, contentType: ‘Content-type: text/plain; charset=iso-8859-1’, // This is the imporant part!!! beforeSend: function(jqXHR) { jqXHR.overrideMimeType(‘text/html;charset=iso-8859-1’); } });

Avoiding content type issues when downloading a file via browser on Android

To make any downloads work on all (and especially older) Android versions as expected, you need to… set the ContentType to application/octet-stream put the Content-Disposition filename value in double quotes write the Content-Disposition filename extension in UPPERCASE Read my blog post for more details: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/

Can’t send a post request when the ‘Content-Type’ is set to ‘application/json’

It turns out that CORS only allows some specific content types. The only allowed values for the Content-Type header are: application/x-www-form-urlencoded multipart/form-data text/plain Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS To set the content type to be ‘application/json’, I had to set a custom content type header in the API. Just removed the last header and added this one: ->header(‘Access-Control-Allow-Headers’, … Read more