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

Call not working with POST #18

Open
pburney opened this issue Jan 16, 2017 · 3 comments
Open

Call not working with POST #18

pburney opened this issue Jan 16, 2017 · 3 comments

Comments

@pburney
Copy link

pburney commented Jan 16, 2017

It looks like with POST the code is just passing the data object to the XHR which isn't actually sending the data to the server. I'm able to workaround this by adding a contentType of "application/x-www-form-urlencoded" and code like the following to the file.

  // Stringify POST query params.
  if (options.type === 'POST' && typeof options.data === 'object' && options.contentType == 'application/x-www-form-urlencoded') {
    var dataToSend = '';
    var stringifyKeyValuePair = function(key, value) {
      return value == null ? '' :
        '&' + encodeURIComponent(key) +
        '=' + encodeURIComponent(value);
    };
    for (var key in options.data) {
      dataToSend += stringifyKeyValuePair(key, options.data[key]);
    }
    options.data = dataToSend.substring(1);
  }

Am I doing something wrong here? data is a standard javascript object with key/value pairs.

      type: 'POST',
      url: 'myapiurl',
      data: data,
      contentType: 'application/x-www-form-urlencoded',
      success: function(results) {
      },
      error: function(results) {
      }
@akre54
Copy link
Owner

akre54 commented Jan 17, 2017

I'm actually surprised to hear this. I was under the impression a content-type isn't required with a POST. Can you do some digging to find out the bare minimum change that would be required to fix this in the library? Maybe start with a plain XHR and a simple HTTP server first? Thanks!

@akre54
Copy link
Owner

akre54 commented Jan 17, 2017

We could also steal the content-type logic from Fetch. It looks like all we need to do is set it to text/plain;charset=UTF-8.

@pburney
Copy link
Author

pburney commented Jan 18, 2017 via email

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