-1

Need help in understanding on how we can make Ajax request in LWC. I tried importing jquery and use $ajax function but had some issues in loading. Is there a better way ? Problem is i have more than 6mb of data to handle and render in LWC.

Thanks everyone who will share their experience and knowledge.

  • Can you add more context and be more specific? else it might get closed. – Pranay Jaiswal Feb 14 '19 at 20:48
  • I want to make a get request in lightning webcomponent js. Tried it using importing jquery and calling ajax. Is there a another standard way of doing in LWC ? – Anshul Agrawal Feb 14 '19 at 20:54
2

In general if you want the standard way to do this you can use XHR or Fetch.

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

You want to be mindful of how often you will fire the request in your component. From the sounds of it you are creating a loader for a large dataset.

  • Thanks. Already did a standard way. But looking forward to a better approach in lwc const Http = new XMLHttpRequest(); const url='abc.com?no_cache=false'; Http.setRequestHeader('Authorization', 'XXXXX'); Http.setRequestHeader('Content-Type', 'application/json'); Http.open("GET", url); Http.send(); Http.onreadystatechange=(e)=>{ console.log(Http.responseText) } – Anshul Agrawal Feb 14 '19 at 23:29
  • yes, its more than 12mb that is why i want to handle in js and render it on a data visualization library – Anshul Agrawal Feb 14 '19 at 23:30
  • Hi Kevin, welcome to SFSE. Please take a moment to scroll through the tour and read How to Answer. Please use statements rather than asking questions when posting an Answer. – Adrian Larson Feb 15 '19 at 3:19
  • I am not sure that I understand the core issue you are having, you mentioned that the jQuery $ajax function had issues. What were the issues with $ajax? Was the XHR request not working as well? – Kevin Hill Feb 15 '19 at 4:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.