<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 解析错误

        Parse error using Remotipart(使用 Remotipart 解析错误)

        <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 解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  Rails 3.1 ajax:success handling(Rails 3.1 ajax:成功处理)
                  ExecJS::ProgramError: SyntaxError: Reserved word quot;functionquot;(ExecJS::ProgramError: SyntaxError: 保留字“function)
                  Infinite scroll and will_paginate appending the #39;next page#39; of items multiple times(无限滚动和 will_paginate 多次附加项目的“下一页)
                  Set of CoffeeScript/JavaScript classes and methods available to rest of Rails app(一组可供 Rails 应用程序使用的 CoffeeScript/JavaScript 类和方法)
                    <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>
                              <tbody id='QGJpl'></tbody>