2014-07-15 37 views
0

我已閱讀並應用了一些類似的解決方案,但到目前爲止效果不佳。ajaxForm:如何擺脫'<pre>' and '</pre>'的迴應?

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> 

西納特拉

post '/update' do 
    ... 
    content_type :json 
    { :success => true }.to_json 
end 

當我運行它,之後點擊 「提交」,我收到警告:

<pre>{"success":true}</pre> 

這個 「預」 的事情是真的惱人的,這阻止了parseJSON的正確調用。我可以做一些字符串操作來刪除它。但我想有更好的解決方案。

感謝您的幫助。

+0

來吧,沒有答案呢?! – user180574

回答

0

只要回答我,

類似這樣的問題

http://stackoverflow.com/questions/908975/strange-behavior-using-ajax-form-ajaxform 

,並按照連結此

http://www.sencha.com/forum/archive/index.php/t-17248.html 

簡短的回答,

變化 「CONTENT_TYPE:JSON」 到「content_type:html」

那麼「預」將消失