Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html in response instead of Json #136

Open
russo-matrosso opened this issue Nov 2, 2015 · 3 comments
Open

Html in response instead of Json #136

russo-matrosso opened this issue Nov 2, 2015 · 3 comments

Comments

@russo-matrosso
Copy link

Hi.
I am using Remotipart to upload files in my project.
Here is my form:

= form_for [@question, @answer], remote: true, data: { type: :json }  do |f|
      p
        = f.label :body, 'Your answer'
        .answer-errors
        = f.text_area :body
      p
        = f.fields_for :attachments do |a|
          = a.label :file
          = a.file_field :file
      = f.submit 'Create answer'

In my controller I use active model serializers to generate json:

respond_to do |format|
      if @answer.save
        format.json {render json: @answer, root: false, status: 200}

Then I parse it and use handlebars templates:

this.$form.bind 'ajax:success', (e, data, status, xhr) ->
      response = $.parseJSON(xhr.responseText);
      $('.answers').append(HandlebarsTemplates['answer'](response))

Everything works perfect if I don't attach file, but if a file attached I get this in my response:

<textarea data-type="application/json" data-status="200" data-statusText="OK">{"id":253,"body":"asdfasdf","user":{"id":3,"email":"[email protected]"},"question":{"id":2}}</textarea>

I read the topic #85 but it didn't help.
Is there a way for remotipart not to overwrite the response?

@sfoop
Copy link

sfoop commented Dec 3, 2015

I ran into this, and it was because jquery fileupload was also in the Gemfile. It also wraps the result in a textarea, so the result gets double-wrapped in textarea tags. In my case I was able to remove jquery fileupload from the project.

@argamontaia
Copy link

I have this problem as well for a CSV download. Any way to disable the textarea wrapping?

@davidgeere
Copy link

I am dealing with the same issue and #85 also doesn't solve for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants