Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle data returned from .ajaxSubmit() call?
    text
    copied!<p>I am using the Jquery Form Plugin to submit a forms data like this.</p> <pre><code> $('#AddLocalImageForm').ajaxSubmit({ beforeSubmit: function() { alert('b4'); }, success: function(data) { alert('afa');}, dataType: 'json' }); &lt;form id="AddLocalImageForm" action="Service/UploadCustImage.ashx" method="post" enctype="multipart/form-data"&gt; &lt;input type="file" name="CustImage" id="CustImage" /&gt; &lt;br /&gt; &lt;label for="ImageName"&gt;Name&lt;/label&gt; &lt;input type="text" name="ImageName" id="ImageName"/&gt; &lt;br /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p>The page I am posting data to is an ashx page that has </p> <pre><code>context.Response.ContentType = "application/json"; </code></pre> <p>and returns data with a </p> <pre><code>context.Response.Write(JsonData); </code></pre> <p>I can see everything is posted properly and I am getting the corect Json Data back but I am always prompted to download the Json data from my browser. What I want to do is be able to take the returned data in the background and update some Dom elements. The beforeSubmit Function executes but the success function never does. If I copy the code from the plugin <a href="http://jquery.malsup.com/form/#ajaxSubmit" rel="nofollow">sample</a> page I get the same thing.</p> <p>How can I make it so the returned data is handled by the function rather than prompting me to download?</p> <p><strong>Update:</strong> So if I change the content type on the ashx page that handles the posted data to </p> <pre><code>context.Response.ContentType = "text/html"; </code></pre> <p>I am no longer prompted to download the file but I am still unable to handle the returned data because the success function never executes. Do I need to tell it that it succeeded or if data is returned does it just assume success?</p>
 

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