Just to address your comments first; I set the headers to application/json and now I get a download dialog (with or without html in the json) The addUpload function doesn't get called which is the problem. In any event this is what it looks like: function addUpload(data) { alert('addUpload called...'); if (data.status == 'success') { alert('Upload Succeeded'); $(".hasbeenattached").append(data.newUpload); } else { alert('Please correct errors with your upload.'); } } </script>
(none of the alerts were firing when there was html in the json, without html it did get called.) This issue seems to be related to the form plugin http://malsup.com/jquery/form/ I am speculating that the root of the issue is because my ajaxSubmit is submitting a file. Which the form plugin does some trickery with to switch it to an iframe (because you can't submit files over ajax). I can't be the only person submitting files via ajax and trying to get a json object back. I am sure I am making a really basic mistake. Any light you can shine would be a huge help. -Ryan On Aug 17, 7:33 pm, MorningZ <morni...@gmail.com> wrote: > First, in PHP you should specify the content-type to be "text/plain" > or "application/json".... leaving it alone as "text/html" could > potentially cause confusion > > Second, you should show what function "addUpload" is/does > > On Aug 17, 4:48 pm, Ryan <ohsm...@gmail.com> wrote: > > > > > I am having problems with the return data from the jquery form plugin > > when one of the values contains html. I am not sure if this is a > > jquery issue or a for plugin issue. > > > My javascript looks like this: > > > var uploadOptions = { > > dataType: 'json', > > url: '/uploads/upload.json', > > success: addUpload > > }; > > $("input[name='upload']").click(function() { > > $(this).parents("form:first").ajaxSubmit( uploadOptions ); > > return false; > > }); > > > The response data that is generated is: > > {"status":"success","validationErrors":null,"newUpload":"\n\t<br><img > > src='http:\/\/www.google.ca\/intl\/en_ca\/images\/logo.gif'>"} > > > What happens is the data from the response seems to get automatically > > inserted into the DOM rather than passed to the addUpload function. > > The addUpload function is not being called at all unless... I change > > the response data to: > > {"status":"success","validationErrors":null,"newUpload":"\n\tNot > > Html"} > > > At which point the addUpload call back is called with the data json > > object passed. > > > The response headers of the data with the HTML are the same as without > > the html: > > Response Headers > > Date Mon, 17 Aug 2009 20:38:38 GMT > > Server Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8j DAV/2 PHP/ > > 5.2.9 > > X-Powered-By PHP/5.2.9 > > P3P CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM" > > Content-Length 134 > > Keep-Alive timeout=5, max=100 > > Connection Keep-Alive > > Content-Type text/html