Reputation: 6094
I've read and also applied some similar solutions, but so far not get working well.
html
<form id="update-form" action="/update" enctype="multipart/form-data" method="post">
<input type="file" name="file" single />
<input type="submit" value="submit />
</form>
<script>
$(function() {
$('#update-form').ajaxForm( {
success: function(data) {
alert(data);
}
} );
} );
</script>
sinatra
post '/update' do
...
content_type :json
{ :success => true }.to_json
end
When I run this, after clicking "submit", I receive in alert:
<pre>{"success":true}</pre>
This "pre" thing is really annoying which prevents proper call of parseJSON. I could do some string manipulation to remove it. But I would like to have better solution.
Thanks for the help.
Upvotes: 0
Views: 1512
Reputation: 6094
Just answer myself,
similar to this question
http://stackoverflow.com/questions/908975/strange-behavior-using-ajax-form-ajaxform
and follow the link to this
http://www.sencha.com/forum/archive/index.php/t-17248.html
Short answer,
change "content_type :json" to "content_type :html"
then "pre" will disappear
Upvotes: 1