【发布时间】:2014-03-12 23:51:35
【问题描述】:
我正在尝试将表单从一个 rails 应用程序发布到另一个托管在不同域上并包括文件的表单。
我尝试过:
$(document).on("click", ".application-form .submission input", function(e){
e.preventDefault();
var form = $(".application-form form");
var data = new FormData(form);
var url = "http://example.com/action";
$.ajax({
url: url,
type: 'POST',
success: function(){
alert('success');
},
error: function(){
alert('error');
},
data: data,
cache: false,
contentType: false,
processData: false
});
});
但是远程服务器没有收到任何数据,params 只包含控制器名称和操作。
我也尝试过使用 remotipart 并使用form_for(@application, url: "http://example.com/action", html: {multipart: true}, remote: true) 设置我的表单,如果我包含一个文件,服务器会收到[object Object] 而不是正确的参数名称和值。如果我不包含文件,则参数会正确发送和接收,但我需要在上传时包含文件。
当我包含一个文件时,是什么导致[object Object] 替换了我的所有表单数据?使用远程 1.2.1。而且我见过this,它不适用。
【问题讨论】:
标签: ruby-on-rails ajax forms cors