ajaxForm:如何摆脱&#39; <pre>&#39; and &#39;</pre>&#39;在回应?

时间:2014-07-15 01:09:37

标签: ajax json ajaxform

我已阅读并应用了一些类似的解决方案,但到目前为止还没有很好地运作。

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

当我运行此功能时,点击&#34;提交&#34;后,我会收到警告:

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

这&#34; pre&#34;事情真的很烦人,这会阻止正确调用parseJSON。我可以做一些字符串操作来删除它。但我希望有更好的解决方案。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

回答自己,

与此问题类似

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

并点击此链接

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

简短回答,

更改&#34; content_type:json&#34; to&#34; content_type:html&#34;

然后&#34; pre&#34;将消失

相关问题