Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery ajax form success callback not being called
    primarykey
    data
    text
    <p>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.</p> <p>I'm using the JQuery Ajax Form Plugin, jquery.form.js found at <a href="http://jquery.malsup.com/form/" rel="noreferrer">http://jquery.malsup.com/form/</a> 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.</p> <p>I don't believe this is an issue with how I'm sending the json as I have a modularized <code>json_wrapper()</code> function that I'm using in multiple places in this same application.</p> <p>Here is what my form looks after Django templates are applied:</p> <pre><code>&lt;form method="POST" enctype="multipart/form-data" action="/test_suites/active/upload_results/805/"&gt; &lt;p&gt; &lt;label for="id_resultfile"&gt;Upload File:&lt;/label&gt; &lt;input type="file" id="id_resultfile" name="resultfile"&gt; &lt;/p&gt; &lt;/form&gt; </code></pre> <p>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.</p> <p>Here is the controlling javascript code:</p> <pre><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(options); return false; }); $form.ajaxSubmit(options); } </code></pre> <p>As you can see, I've gotten desperate to see the success callback function work and simply have an alert message created on success. However, we never reach that call. Also, the <code>error</code> function is not called and the <code>beforeSubmit</code> function is executed.</p> <p>The file that I get back has the following contents:</p> <pre><code>{"count": 18, "failed": 0, "completed": 18, "success": true, "trasaction_id": "SQEID0.231"} </code></pre> <p>I use 'success' here to denote whether or not the server was able to run the post command adequately. If it failed the result would look something like:</p> <pre><code>{"success": false, "message":"&lt;error_message&gt;"} </code></pre> <p>Your time and help is greatly appreciated. I've spent a few days on this now and would love to move on.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload