相关文章推荐
坏坏的丝瓜  ·  独家 | ...·  3 周前    · 
坏坏的丝瓜  ·  Orca 配置 GUI - ...·  5 月前    · 
坏坏的丝瓜  ·  反射获取Field - ALID Blog·  5 月前    · 
坏坏的丝瓜  ·  PostgreSQL 时间函数 ...·  8 月前    · 
坏坏的丝瓜  ·  groovy findall in list·  9 月前    · 
坏坏的丝瓜  ·  Simultaneous ...·  10 月前    · 
坏坏的丝瓜  ·  King's Uncle·  11 月前    · 
坏坏的丝瓜  ·  闲谈Monaco ...·  11 月前    · 
爱健身的跑步鞋  ·  机电产品进口管理办法·  23 分钟前    · 
飘逸的马克杯  ·  【GIT SourceTree】_<git ...·  23 分钟前    · 
博学的豌豆  ·  Team Foundation ...·  23 分钟前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
   var xhr = new XMLHttpRequest();
   xhr.open(method, url);
   xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
   xhr.onload = requestComplete;
   xhr.send(params);

I know Im going to encounter errors because there's a proper way of formatting my "request body". It looks like a mixture of array and JSON so Im asking for your help how to format it correctly.

var xhr = new XMLHttpRequest();
   xhr.open(method, url);
   xhr.setRequestHeader('Authorization', 'Bearer ' + access_token);
   xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
   xhr.onload = requestComplete;
   xhr.send(JSON.stringify(params));

It looks like you just needed to stringify your params before passing them to send()

Have you tried it out yet? You can't just assume that you are going to encounter errors. You wouldn't know unless you try. Try you first method, if it fails, you would have discovered a way that won't work. Then you find other ways that would work, that's how we learn. It is from the errors and failures that we learn not from the successes.

That being said, if your method fails as you have assumed, try to use JSON.stringify on the params before sending it just like this

xhr.send(JSON.stringify(params))

That should work.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章
坏坏的丝瓜  ·  King's Uncle
11 月前