Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

End of input when no JSON is returned with 200 OK from server. #14

Closed
constantm opened this issue Oct 21, 2015 · 3 comments
Closed

End of input when no JSON is returned with 200 OK from server. #14

constantm opened this issue Oct 21, 2015 · 3 comments

Comments

@constantm
Copy link

Awesome addon! However, when used with Rails and response is set with the following:

respond_to do |format|
  format.json { head :ok }
end

You get an error:

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at jQuery.parseJSON (http://localhost:4200/assets/vendor.js:7736:14)
    at ajaxConvert (http://localhost:4200/assets/vendor.js:8013:19)
    at done (http://localhost:4200/assets/vendor.js:8429:15)
    at XMLHttpRequest.<anonymous> (http://localhost:4200/assets/vendor.js:8819:9)

However, when you add some actual JSON content to the response, it seems to work fine.

@mike183
Copy link
Contributor

mike183 commented Oct 22, 2015

I ran into this issue yesterday. The reason you are seeing an error is because ember-ajax expects a JSON response by default (see this line), and as a result is attempting to parse the response as JSON.

If you're not returning a JSON response, you should update the dataType attribute to something more appropriate. For possible values, see jQuery's $.ajax() docs for dataType.

e.g.

this.get("ajax").request("/some/request/url/", {
  dataType: "text"
});

@jcbvm
Copy link
Contributor

jcbvm commented Nov 13, 2015

I think this lib should not force the dataType to be JSON, the default auto detection of jQuery is just fine.

@alexlafroscia
Copy link
Collaborator

Considering that @mike183 posted the solution to this issue, I'm going to close it out.

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

No branches or pull requests

4 participants