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

dataType doesnt work? #699

Closed
max-degterev opened this issue Feb 19, 2013 · 3 comments
Closed

dataType doesnt work? #699

max-degterev opened this issue Feb 19, 2013 · 3 comments

Comments

@max-degterev
Copy link

Hi! Having a bit of a problem here

@_req = $.ajax(
  url: app.api('suggest', place)
  dataType: 'json'
  success: _.bind(@renderSuggest, @)
  error: _.bind(@clearSuggest, @)
)

works when

@_req = $.ajax(
  url: app.api('suggest', place)
  success: _.bind(@renderSuggest, @)
  error: _.bind(@clearSuggest, @)
)

doesnt. Server headers are fine, getting unparsed string response from the server anyway.

Tried this as a workaround:

app.dom.doc.on('ajaxBeforeSend', (e, xhr, options)->
  options.dataType = 'json' unless options.dataType
)

Doesnt work either. options already have dataType == 'json'

@mislav
Copy link
Collaborator

mislav commented Feb 19, 2013

What is the Content-type of server response? Is it "application/json"? If it's not, you have to explicitly set dataType in order to have JSON automatically parsed

@max-degterev
Copy link
Author

Running server with node, expressjs

dataType set:
Screen Shot 2013-02-19 at 8 10 25 PM

dataType not set:
Screen Shot 2013-02-19 at 8 11 37 PM

(note the Accept:/)

@mislav mislav closed this as completed in 9b77aca Mar 3, 2013
@mislav
Copy link
Collaborator

mislav commented Mar 3, 2013

Thanks! It should work now. In your case, things should work even without dataType specified explicitly

lopper pushed a commit to buddydvd/zepto that referenced this issue Apr 24, 2013
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

2 participants