First of all I'd like to ask that you don't suggest I turn to a jQuery plugin to solve my issue. I'm just not willing to make my app work with a plugin (and it prevents me from learning!)
I have a form with a bunch of fields that I'm passing to my backend via the use of jQuery's $.post()
This is what I have as my jQuery function:
$.post(
"/item/edit",
$("#form").serialize(),
function(responseJSON) {
console.log(responseJSON);
},
"html"
);
This is how I opened my form:
<form action="http://localhost/item/edit" method="post" accept-charset="utf-8" class="form-horizontal" enctype="multipart/form-data">
This was auto generated by codeigniter's form_open()
method (hence why action="" has a value. Though this shouldn't matter because I don't have a submit button at the end of the form)
Within my #form
I have this as my file input: <input type="file" name="pImage" />
When the appropriate button is hit and the $.post()
method is called, I have my backend just print the variables like so: print_r($_POST)
and within the printed variables the 'pImage' element is missing. I thought that maybe files wouldn't come up as an element in the array so I went ahead and just tried to upload the file using this codeigniter function: $this->upload->do_upload('pImage');
and I get an error: "You did not select a file to upload."
Any idea as to how I can overcome this problem?