2013-05-09 92 views
1

我正在使用Remotipart上传文件。 Rails-Controller处理文件,但我不知道如何获得以下ajax响应。这是我的js代码。Remotipart获取ajax响应

$file.children(".description").html(
    '<%= form_for FileObject.new, :url => file_object_index_path , :html => { :multipart => true }, :remote => true do |f| %>' + 
    '<div class="field">' + 
    '<%= f.label :file %>' + 
    '<%= f.file_field :file %>'+ 
    '</div>' + 
    '<input type="hidden" name="directory_object_id" value="' + current_directory.id +'" />' + 
    '<div class="actions">' + 
      '<%= f.submit %>' + 
      '</div>' + 
    '<% end %>' 
); 
$("form").bind('ajax:success', function(){ 
    alert("success"); 
}); 

也许有人已经解决了这个问题。

回答

5

而是结合ajax:success,试试这个:

$("form").bind("ajax:complete", function(e, data, status, error){ 
    if (data.status === 200 || data.status === 201) { 
     ... 
    } 
}) 

我有麻烦使用remotipart时结合AJAX的支持,并已在过去使用上述解决办法。

+1

这可能是你的回应是HTML而不是默认的JS remotipart。看到我对这个类似的问题的答复有关如何解决这个更优雅:http://stackoverflow.com/questions/14508260/parse-error-using-remotipart – 2013-05-24 01:06:58