Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with AJAX Upload Script in mvc
    primarykey
    data
    text
    <p>I found this ajax file upload script here <a href="http://www.phpletter.com/Demo/AjaxFileUpload-Demo/" rel="nofollow">http://www.phpletter.com/Demo/AjaxFileUpload-Demo/</a></p> <p>Which is supposed to add ajax functionality to my file upload form</p> <pre><code>&lt;div id="dialog" title="Upload Image"&gt; &lt;% Html.BeginForm("Upload", "BugTracker", FormMethod.Post,new { id="uploadForm", enctype = "multipart/form-data"}); %&gt; Select a file: &lt;input type="file" name="file" id="file" /&gt; &lt;h6&gt;Upload a screenshot related to the ticket&lt;/h6&gt; &lt;input type="submit" class="button" value="Upload" id="upload" onclick="uploadImage();" name="submit" /&gt; &lt;%Html.EndForm();%&gt; &lt;/div&gt; </code></pre> <p>And I have set up a function to be called when my upload form is submitted like so:</p> <pre><code>function uploadImage() { var action = $("#uploadForm").attr('action'); $.ajaxFileUpload({ url: action, secureuri: false, fileElementId: 'file', dataType: 'json', success: function (data, status) { $("#RelatedFileName").val() = data.FileName; $("#dialog").dialog("close"); } }); return false; } </code></pre> <p>but it is skipping right over the success callback function, and the browser asks if I would like to download the json file. Here's a peek at my upload action:</p> <pre><code> [HttpPost] public ActionResult Upload(HttpPostedFileBase file) { Regex imageFilenameRegex = new Regex(@"(.*?)\.(jpg|jpeg|png|gif)$"); if (file != null) { if (!imageFilenameRegex.IsMatch(file.FileName)) { return JavaScript("alert('invalid file. you must upload a jpg, jpeg, png, or gif');"); } else { string filePath = Path.Combine(HttpContext.Server.MapPath("~/Uploads"), Path.GetFileName(file.FileName)); file.SaveAs(filePath); return Json(new { FileName = "/Uploads/" + file.FileName }); } } else { return JavaScript("alert('seriously? select a file to upload before hitting the upload button.');"); } } </code></pre> <p>I've used jQuery.post and it will hit the controller action but file will be null, but at least errors would pop up in their alert boxes, so that is why I sought out another option. Now it hits the controller action and the file gets uploaded, but it isn't handling any response. Any help is appreciated.</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.
 

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