Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Rails AJAX表单提交_Jquery_Ruby On Rails_Ajax - Fatal编程技术网

Jquery Rails AJAX表单提交

Jquery Rails AJAX表单提交,jquery,ruby-on-rails,ajax,Jquery,Ruby On Rails,Ajax,我想通过AJAX提交表单。当我提交表单时,它应该发送一个ajax并淡入id为Step2的div,淡出当前div。我使用的是jQuery 1.8.0,提交时控制台中出现了这个错误 NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindow.getComputedStyle] [Break On This Error] ...=[]),o&&a

我想通过AJAX提交表单。当我提交表单时,它应该发送一个ajax并淡入id为Step2的div,淡出当前div。我使用的是jQuery 1.8.0,提交时控制台中出现了这个错误

 NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)      [nsIDOMWindow.getComputedStyle]
[Break On This Error]   

...=[]),o&&(e=" "+e);while(e){k=!1;if(j=B.exec(e))e=e.slice(j[0].length),k=d.push({...
这是我的HTML:

<div id="stepOne">
<%= form_for @program do |f| %>
    <div>
    <label for="exerciseName">Title For Your Program</label>
    <%= f.text_field :title, :name => "exerciseName", :required => "required", :maxlength => "40" %>
    </div>
    <div>
    <label for="exerciseName">Detailed Info For Your Program</label>
    <%= f.text_area :details %>
    </div>

<%= f.submit "Next Step", :class => "exbuttons button-small red rounded3", :id =>"stepOneButton" %>
<% end %>
</div>
这是我的Javascript文件

function stepOne(){
    $('#new_program').submit(function(event){
        event.preventDefault();
        var f = $(this);
        f.find('input[type="submit"]').attr("disabled", true);
        $.ajax({
            type: f.attr("method"),
            url: f.attr("action"),
            data: f.serialize(),
            complete: function(){
                f.find('input[type="submit"]').attr("disabled", false);
            },

            success : function(data){
                console.log(data);
                $(this).fadeOut();
                $('#stepTwo').delay(400).fadeIn();
            },

            error : function(xhr, status){
                console.log(status);
            }
        });


    });
}

NS_ERROR_失败似乎表明URL错误或rails控制器出错

检查脚本调用的URL是否确实正确,如果URL正确,可以在不使用ajax的情况下运行它以查看rails返回的错误页面

您似乎也没有使用respond_to,因此可能不需要包含它

function stepOne(){
    $('#new_program').submit(function(event){
        event.preventDefault();
        var f = $(this);
        f.find('input[type="submit"]').attr("disabled", true);
        $.ajax({
            type: f.attr("method"),
            url: f.attr("action"),
            data: f.serialize(),
            complete: function(){
                f.find('input[type="submit"]').attr("disabled", false);
            },

            success : function(data){
                console.log(data);
                $(this).fadeOut();
                $('#stepTwo').delay(400).fadeIn();
            },

            error : function(xhr, status){
                console.log(status);
            }
        });


    });
}