<legend id='tXwvK'><style id='tXwvK'><dir id='tXwvK'><q id='tXwvK'></q></dir></style></legend>
        <i id='tXwvK'><tr id='tXwvK'><dt id='tXwvK'><q id='tXwvK'><span id='tXwvK'><b id='tXwvK'><form id='tXwvK'><ins id='tXwvK'></ins><ul id='tXwvK'></ul><sub id='tXwvK'></sub></form><legend id='tXwvK'></legend><bdo id='tXwvK'><pre id='tXwvK'><center id='tXwvK'></center></pre></bdo></b><th id='tXwvK'></th></span></q></dt></tr></i><div id='tXwvK'><tfoot id='tXwvK'></tfoot><dl id='tXwvK'><fieldset id='tXwvK'></fieldset></dl></div>
      1. <tfoot id='tXwvK'></tfoot>
          <bdo id='tXwvK'></bdo><ul id='tXwvK'></ul>

        <small id='tXwvK'></small><noframes id='tXwvK'>

      2. 使用 Remotipart 解析错误

        时间:2024-04-19

        <small id='AJLID'></small><noframes id='AJLID'>

        <tfoot id='AJLID'></tfoot>

            <bdo id='AJLID'></bdo><ul id='AJLID'></ul>

                <tbody id='AJLID'></tbody>

              <i id='AJLID'><tr id='AJLID'><dt id='AJLID'><q id='AJLID'><span id='AJLID'><b id='AJLID'><form id='AJLID'><ins id='AJLID'></ins><ul id='AJLID'></ul><sub id='AJLID'></sub></form><legend id='AJLID'></legend><bdo id='AJLID'><pre id='AJLID'><center id='AJLID'></center></pre></bdo></b><th id='AJLID'></th></span></q></dt></tr></i><div id='AJLID'><tfoot id='AJLID'></tfoot><dl id='AJLID'><fieldset id='AJLID'></fieldset></dl></div>

              • <legend id='AJLID'><style id='AJLID'><dir id='AJLID'><q id='AJLID'></q></dir></style></legend>
                1. 本文介绍了使用 Remotipart 解析错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I'm using remotipart to upload and upgrade images using ajax, the problem is when I edit an item, ajax updates the data, but remotipart(https://github.com/leppert/remotipart) returns a 'parse error' for image update.

                  This is how my form looks like:

                  = form_for(Achievement.new), html: {multipart: true , remote: true} do |f|
                            = f.text_field :name
                            = f.text_area :description
                            = f.file_field :image
                            = f.submit 'Send'
                  

                  I'm using a single form to create, edit and delete the 'Achievements'. Here's my js:

                  constructor: ->
                      $('.edit_button').click ->
                        $.ajaxSettings.dataType = "json"
                        @id = $(this).data('id')
                        @content = $(this).parent()
                        @name = $('.form_achievement #name')
                        @description = $('.form_achievement #description')
                        @image = $('.form_achievement .avatar img')
                        @button = $('.form_achievement form input:submit')
                        @form = $('.form_achievement form')
                  
                        #Load data to edit on form
                        $.ajax
                          type: 'get'
                          url: "/en/private/achievements/#{@id}/edit/"
                  
                          success: (data) =>
                            alert 'edit'
                            @name.val(data.achievement.name)
                            @description.val(data.achievement.description)
                            @stat.html(data.achievement.stat)
                            @value.val(data.achievement.value)
                            @image.prop 'src', data.image
                  
                          #Change method of the form to put and bind event  
                          $.ajaxSettings.dataType = "json"
                          @form.attr('method','put')
                          $('.form_achievement form').attr('action', "/en/private/achievements/#{@id}")
                          $('#achievement_form.accordion .form_achievement').unbind('click', NewAchievement)
                  
                          @form.bind 'ajax:success', (xhr, data, status) =>
                            @content.slideUp 'slow', ->
                              $(this).remove()
                            alert 'Edit'
                  
                          @form.bind 'ajax:error', (event, response, error) =>
                            alert error
                          @button.bind 'change', => @changeButton()
                  
                  
                          error: (data) ->
                            alert 'error'
                  
                    changeButton: ->
                      @form.submit()
                  

                  This solves my problem when I'm trying to do an edit without change image, but when I do an edit trying to upgrade to a new image, returns me a 'parse error'. Can anyone help me?

                  解决方案

                  You're very likely getting a parse error because your response is actually HTML.

                  The problem is that by default remotipart assumes the server response was JS. You can set the data type when rendering the form, in your case:

                  form_for(Achievement.new), html: {:'data-type' => :html, :multipart => true, :remote => true}
                  

                  Or it can be done in JS like so:

                  @form.bind 'ajax:remotipartSubmit', (event, xhr, settings) =>
                      settings.dataType = "html *"
                  

                  这篇关于使用 Remotipart 解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 JavaScript/CoffeeScript 中优雅地循环链接调用? 下一篇:在 Rails 4 中显示所选类别的子类别

                  相关文章

                    <bdo id='QGJpl'></bdo><ul id='QGJpl'></ul>

                  1. <tfoot id='QGJpl'></tfoot>
                    <i id='QGJpl'><tr id='QGJpl'><dt id='QGJpl'><q id='QGJpl'><span id='QGJpl'><b id='QGJpl'><form id='QGJpl'><ins id='QGJpl'></ins><ul id='QGJpl'></ul><sub id='QGJpl'></sub></form><legend id='QGJpl'></legend><bdo id='QGJpl'><pre id='QGJpl'><center id='QGJpl'></center></pre></bdo></b><th id='QGJpl'></th></span></q></dt></tr></i><div id='QGJpl'><tfoot id='QGJpl'></tfoot><dl id='QGJpl'><fieldset id='QGJpl'></fieldset></dl></div>

                    <small id='QGJpl'></small><noframes id='QGJpl'>

                      <legend id='QGJpl'><style id='QGJpl'><dir id='QGJpl'><q id='QGJpl'></q></dir></style></legend>