---
title: "Ajax picture upload fails on iOS generates internal server error"  
description: "Ajax picture upload fails on iOS generates internal server error"  
author: "David Miller"  
published: 2014-10-28  
updated: 2014-10-28  
canonical: https://www.mindstick.com/forum/2445/ajax-picture-upload-fails-on-ios-generates-internal-server-error  
category: "iphone"  
tags: ["iphone", "ios", "ios 7"]  
reading_time: 2 minutes  

---

# Ajax picture upload fails on iOS generates internal server error

I implemented an ajax [file upload](https://www.mindstick.com/articles/13047/file-upload-and-download-in-mvc) Everything [works fine](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why) in all browsers, but [Safari](https://www.mindstick.com/forum/453/font-weight-bold-property-not-support-in-ie-opera-safari-chrome) on iOS. As [response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt) I get an [Internal Server Error](https://www.mindstick.com/forum/159408/an-api-request-returns-a-500-internal-server-error-how-to-fix-this-error).

I checked my serverside code, but there's nothing wrong. I even get the error, if I write a die(); at the first line of code in the serverside PHP script. It seems as if Safari uploads the [picture](https://answers.mindstick.com/qa/38554/name-the-oscar-winning-sound-designer-who-became-the-first-asian-to-win-the-award-for-best-sound-for-documentary-india-s-daughter-at-the-coveted-motion-picture-sound-editors-63rd-annual-golden-reel-awards) wrongly. Maybe somebody can help me fix this bug. Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## This is the HTML-Code:

```
<input type="file" id="pict" accept="image/*"><input type="text" id="field1"><input type="text" id="field2"><button id="send">Send</button>
```

And this the [Javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript):\

```
    var files = false;     $('#pic').on('change', prepareUpload);     function prepareUpload(event) {        files = event.target.files;    }     $("body").on("click", "#send", function () {        uploadTB();    });     function uploadTB() {        var postdata = new FormData();        if (files !== false) {            $.each(files, function (key, value) {                postdata.append(key, value);            });        }        postdata.append("field1", $("#field1").val());        postdata.append("field2", $("#field2").val());        $.ajax({            url: 'http://example.org/index.php',            type: 'POST',            data: postdata,            cache: false,            processData: false,            contentType: false,            success: function (data) {                console.log("sucess");            },            error: function (jqXHR, textStatus, errorThrown) {                console.log(jqXHR, textStatus, errorThrown);            }        });    }
```

## Replies

### Reply by Tom Cruser

try this:

```
    var files = false;     $('#pic').on('change', prepareUpload);     function prepareUpload(event) {        files = event.target.files;    }     $("body").on("click", "#send", function () {        uploadTB();    });     function uploadTB() {        var postdata = new FormData();        if (files !== false) {            $.each(files, function (key, value) {                postdata.append(key, value);            });        }        postdata.append("field1", $("#field1").val());        postdata.append("field2", $("#field2").val());        $.ajax({            url: 'http://example.org/index.php',            type: 'POST',            data: formData,            mimeType: "multipart/form-data",            contentType: false,            cache: false,            processData: false,            success: function (data) {                console.log("sucess");            },            error: function (jqXHR, textStatus,errorThrown) {                console.log(jqXHR, textStatus,errorThrown);            }        });    }
```


---

Original Source: https://www.mindstick.com/forum/2445/ajax-picture-upload-fails-on-ios-generates-internal-server-error

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
