I'm trying to upload a file using "AJAX", process data in the file and then return some of that data to the UI so I can dynamically update the screen.
I'm using the JQuery Ajax Form Plugin, jquery.form.js found at http://jquery.malsup.com/form/ for the javascript and using Django on the back end. The form is being submitted and the processing on the back end is going through without a problem, but when a response is received from the server, my Firefox browser prompts me to download/open a file of type "application/json". The file has the json content that I've been trying to send to the browser.
I don't believe this is an issue with how I'm sending the json as I have a modularized json_wrapper() function that I'm using in multiple places in this same application.
Here is what my form looks after Django templates are applied:
<form method="POST" enctype="multipart/form-data" action="/test_suites/active/upload_results/805/">
<p>
<label for="id_resultfile">Upload File:</label>
<input type="file" id="id_resultfile" name="resultfile">
</p>
</form>
You won't see any submit buttons because I'm calling submit with a button else where and am using ajaxSubmit() from the jquery.form.js plugin.
Here is the controlling javascript code:
function upload_results($dialog_box){
$form = $dialog_box.find("form");
var options = {
type: "POST",
success: function(data){
alert("Hello!!");
},
dataType: "json",
error: function(){
console.log("errors");
},
beforeSubmit: function(formData, jqForm, options){
console.log(formData, jqForm, options);
},
}
$form.submit(function(){
$(this).ajaxSubmit(optio