Reputation: 62624
I have a file test.xml that I want to POST up to a URL that accepts POST parameters, Is there a way to use Iframes or some other way in order to get around so that I can post the file to a url via the $.ajax function and associating the user file upload form element to a variable? Note I want the contents of that file to be uploaded and not just a file name.
I want to have something like:
<input type="file" id="thefile"></input>
and in jquery do:
var something = $(#thefile).contentsofthefiletopost;
I would like to do this without page refresh.
Upvotes: 1
Views: 674
Reputation: 1143
Check out the jQuery form plugin, which supports file input types:
http://jquery.malsup.com/form/
You will have to upload via file input, and then use server-side scripting to read the file, in PHP:
<? $xml = file_get_contents($_FILES[0]); print $xml; ?>
Upvotes: 1
Reputation: 3660
http://api.jquery.com/jQuery.post/ is what you need. Just read the docs and it will make sense
Upvotes: 2