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

Invalid JSON responses and ajaxOptions depreciation #5338

Closed
jcheron opened this issue Jan 27, 2018 · 2 comments
Closed

Invalid JSON responses and ajaxOptions depreciation #5338

jcheron opened this issue Jan 27, 2018 · 2 comments

Comments

@jcheron
Copy link

jcheron commented Jan 27, 2018

A Rest API does not always return a valid json response.
if the answer is empty, jQuery displays the following error: see #4207

SyntaxError: Unexpected end of JSON input
at parse ()
at ajaxConvert (jquery.js:8787)
at done (jquery.js:9255)
at XMLHttpRequest. (jquery.js:9548)

Before ds-improved-ajax it was possible to correct this error by modifying the dataType used by jQuery in the ajaxOptions method:

export default DS.RESTAdapter.extend({
  ajaxOptions: function(url, type, options) {
    var hash = this._super(url, type, options);
    // override if it's a POST request (empty response)
    if (type == 'POST') {
      hash.dataType = 'text';
    }
    return hash;
  }
}

What is the recommended solution for this since ajaxOptions is deprecated?

I did not see anything in the methods mentioned to modify the response:

  • methodForRequest to get the HTTP verb
  • urlForRequest to get the URL
  • headersForRequest to get the headers
  • dataForRequest to get the data (query params or request body)
@runspired
Copy link
Contributor

We will not be moving ds-improved-ajax forward, and will be removing it. It's likely you should continue to use ajaxOptions

@runspired
Copy link
Contributor

Closing this because of #5384

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