首页 \ 问答 \ Ajax导致错误:在表单提交上启动POST“/ [object%20Object]”(Ajax causing error: Started POST “/[object%20Object]” on form submit)

Ajax导致错误:在表单提交上启动POST“/ [object%20Object]”(Ajax causing error: Started POST “/[object%20Object]” on form submit)

我正在使用Rails创建一个能够提交联系信息和创建联系对象的页面。 联系人创建的控制器是:

def create
 @contact = Contact.new(contact_params)
 if @contact.save
  render json: @contact, status: :created
 else
  render json: @contact.errors.full_messages, status: :unprocessable_entity
 end
end

与contact_params:

def contact_params
  params.require(:contact).permit(:name, :email, :phone, :company, :message)
end

如果我处理重定向的所有内容,表单提交并创建对象,但我想用JS处理创建。 我之前在表单提交时使用过这种方法没有问题,但出于某种原因我运行时:

$(document).ready(function(){
  $('#new_contact').on('submit', function(ev){
    ev.preventDefault()
    $.post({
      url: $(ev.target).attr('action'),
      data: new FormData(ev.target),
      processData: false,
      contentType: false,
      success: function(data){
        $('#new_contact').append('<div class="col-xs-12 col-sm-6 col-sm-  offset-3"><h3>Thanks for contacting me,' + data.name + '. I will get back to you as soon as I can.</h3></div>')
        document.getElementById('new_contact').reset()
        $('#new_contact input[type="submit"]').prop('disabled', false)
      },
      error: function(error){
        $('#new_contact').append('<div class="col-xs-12 col-sm-6 col-sm-offset-3"><h3>Sorry, I need at least a name and valid e-mail.</h3></div>')
        $('#new_contact input[type="submit"]').prop('disabled', false)
      }
    })
  })
})

它命中了post请求,我的服务器返回错误:

ActionController :: RoutingError(没有路由匹配[POST]“/ [object%20Object]”):

我之前从未遇到过此错误,我不确定如何修复它。 任何帮助表示赞赏。


I'm using Rails to create a page with the ability to submit contact information and create a contact object. The controller for the Contact creation is:

def create
 @contact = Contact.new(contact_params)
 if @contact.save
  render json: @contact, status: :created
 else
  render json: @contact.errors.full_messages, status: :unprocessable_entity
 end
end

with contact_params of:

def contact_params
  params.require(:contact).permit(:name, :email, :phone, :company, :message)
end

The form submits and creates objects fine if I handle everything a redirect but I want to handle the creation with JS. I've used this method before on form submission with no problems but for some reason when I run:

$(document).ready(function(){
  $('#new_contact').on('submit', function(ev){
    ev.preventDefault()
    $.post({
      url: $(ev.target).attr('action'),
      data: new FormData(ev.target),
      processData: false,
      contentType: false,
      success: function(data){
        $('#new_contact').append('<div class="col-xs-12 col-sm-6 col-sm-  offset-3"><h3>Thanks for contacting me,' + data.name + '. I will get back to you as soon as I can.</h3></div>')
        document.getElementById('new_contact').reset()
        $('#new_contact input[type="submit"]').prop('disabled', false)
      },
      error: function(error){
        $('#new_contact').append('<div class="col-xs-12 col-sm-6 col-sm-offset-3"><h3>Sorry, I need at least a name and valid e-mail.</h3></div>')
        $('#new_contact input[type="submit"]').prop('disabled', false)
      }
    })
  })
})

It hits the post request and my server returns with the error:

ActionController::RoutingError (No route matches [POST] "/[object%20Object]"):

I've never encountered this error before and I'm not sure how to go about fixing it. Any help is appreciated.


原文:https://stackoverflow.com/questions/39334455
更新时间:2022-06-06 07:06

最满意答案

好的风格不是首先使用维度语句。 特别是如果你使用隐式类型。 每个变量都应该有一个声明的类型,最好将数组维度放在那里。 使用带有类型声明的属性(Fortran 90+)。

real :: energy_t(20000), nrt(20000)
real, dimension(1000) :: npsh, xx, yy, step, stepz, r1, rr, ic, diffrr

保持线条不要太长。 声明尺寸(形状)的两种方式都是可能的。

如果你需要Fortran 77,你会受到更多限制,但仍然如此

real energy_t(20000), nrt(20000)
real npsh(1000), xx(1000), yy(1000), step(1000), stepz(1000)
real r1(1000), rr(1000), ic(1000), diffrr(1000)

可能更好。

尝试将相关变量分组到一行,将其他变量分组到不同的行。

我还建议声明大小为1000和20000的parameter常量。


Good style is not to use the dimension statement in the first place. Especially if you use implicit typing. Every variable should have a declared type and is better to put the array dimension there. Use attributes with the type declaration (Fortran 90+).

real :: energy_t(20000), nrt(20000)
real, dimension(1000) :: npsh, xx, yy, step, stepz, r1, rr, ic, diffrr

Keep lines not too long. Both ways of declaring size (shape) are possible.

If you need Fortran 77, you are more limited, but still

real energy_t(20000), nrt(20000)
real npsh(1000), xx(1000), yy(1000), step(1000), stepz(1000)
real r1(1000), rr(1000), ic(1000), diffrr(1000)

is probably better.

Try to group related variables on one line and the others on different lines.

I would also suggest to declare parameter constants for the sizes 1000 and 20000.

相关问答

更多
  • 我的5美分 Fortran Wiki是一个很好的起点。 它有关于使用现代Fortran编程的不同方面的文章。 单元测试,调试,通用编程等。同样非常有趣的表格可以在Fortran 2003 Standard编译器支持。 (正如Blklight已经提到的一些2003功能在编译器中不可用,它是比较不同编译器的好地方。) 我是一个C ++的人,但我被困在一些F90项目中。 我建议阅读本课程: 现代Fortran简介 。 MSB提到着名的“Fortran 95/2003解释”,但这本书足够大,内容充实。 相反,上述课 ...
  • 毫无疑问,它是一个变量,它具有用于测量浮点计算的“精度” - 由于某些浮点数的不精确表示,它可能会漂移。 在Fortran中,除非使用编译器选项(或IMPLICIT语句)打开此功能,否则不必声明变量。 以AH和OZ开头的变量会自动考虑REAL变量(IN是整数)。 有问题的编译器可能会或可能不会将变量的内存清零,所以除非它被分配到某处 - 通常是COMMON块 - 它可能是零或某个任意值。 It's undoubtedly a variable holding an "accuracy" used to me ...
  • 这是简短的: real(kind=kr8) :: rnum 在这种情况下,变量或参数kr8在代码中的其他位置指定 - 如果在同一过程中,则在此行的上方;如果通过模块访问,则在不同的文件中。 从它的名字中,可以假设kr8是以这样的方式定义的,即对于某些特定的编译器,它具有双精度浮点数(8字节大小)。 请参阅Fortran编译器文档,了解kind参数对于各种精度和整型和实型变量的范围可以采用的值。 如果你使用强制,你的编译器是gfortran,g95或g77。 kind参数是引入到Fortran 90的一项功 ...
  • 这条线 COMMON/XQANG/SUM(300,10),MDIR,COSTH 通知子程序有一个叫做XQANG的公共块 ,它有一个名为COSTH的元素。 在没有其他信息的情况下,以及该年份的代码中,这很可能是一个real变量。 通用块是早期的Fortran机制,用于跨程序单元共享变量,例如在主程序和子程序之间共享变量。 直接使用相同的公共块声明将在多个位置找到,并具有相同的变量列表。 每个声明都指向相同的变量。 尽管如此,还有一个值得注意的地方。 公共块实际上是共享的内存块,并且不要求每个声明实例标识相同 ...
  • 这主要是由于历史原因。 旧编译器(Fortran IV(66)及之前)实现了主要使用静态内存的程序。 旧机器甚至没有任何堆叠。 因此,程序的行为,因为变量被定义为save 。 变量初始化的前身DATA语句更像是定义静态内存的初始内容(类似于汇编中数据段的指令),这与您从C中知道的调用变量初始化相似。语法变得相似到后来的C变种。 This is mainly due to historical reasons. Old compilers (Fortran IV(66) and before) were im ...
  • 同时引入的result是递归 。 在我们讨论递归函数如何出现之前,对结果变量的含义进行一些澄清。 无论是否使用结果,函数结果始终通过结果变量返回。 1使用result ,结果变量具有指定的名称,如果没有结果变量,则结果变量具有与函数相同的名称。 在后一种情况下,名称的使用是对结果变量的引用,而不是对函数的引用。 所以,如果函数foo有结果变量foo那么我们就不能做直接递归: recursive function foo(n) foo = foo(n-1) ! Oh dear end function ...
  • 错误消息非常明确。 在变量声明中使用的初始化器必须是常量值。 在你的例子中, a不是一个常量。 它应该像这样工作: PROGRAM test3 IMPLICIT NONE INTEGER, PARAMETER :: a=2286 INTEGER :: b=a/3 WRITE(*,*) a, b END PROGRAM test3 因为那时a是一个常数。 The error message is pretty explicit. Initializers using in variabl ...
  • 好的风格不是首先使用维度语句。 特别是如果你使用隐式类型。 每个变量都应该有一个声明的类型,最好将数组维度放在那里。 使用带有类型声明的属性(Fortran 90+)。 real :: energy_t(20000), nrt(20000) real, dimension(1000) :: npsh, xx, yy, step, stepz, r1, rr, ic, diffrr 保持线条不要太长。 声明尺寸(形状)的两种方式都是可能的。 如果你需要Fortran 77,你会受到更多限制,但仍然如此 re ...
  • 语言名称区分大小写。 发布后,我得到: ~/cmt> cmake ./ CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly. Missing variable is: CMAKE_fortran_COMPILER_ENV_VAR CMake Error: Error required internal CMake variable not set, cmake may ...
  • 这是相同的代码,只是现代化。 正如你所看到的那样,它需要一个a , b和c的实数数组,但是FORTRAN非常棒,因为你可以像对待数组那样处理标量 pure subroutine ilocz (a,b,c,n,m) implicit none ! Arguments integer, intent(in) :: n,m real, intent(in) :: a(n,n),b(n,m) real, intent(out) :: c(n,m) ! Local Vars integer :: i,j,k ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。