Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python's urllib.urlopen for javascript

Is there a module written in javascript that's equivalent to python's urllib? In particular, I want something like:

urllib.urlopen(url, data)

which returns an object that supports a blocking fetch. Alternatively, in what other ways could I perform a blocking request to a server using javascript?

like image 701
rjkaplan Avatar asked Mar 29 '26 19:03

rjkaplan


1 Answers

You can use the normal XMLHttpRequest synchronously:

var xhr = new XMLHttpRequest();
xhr.open('POST', url, false);  # third param is sync/async
xhr.send(data);
var response = xhr.responseText;
like image 67
Daniel Roseman Avatar answered Apr 01 '26 09:04

Daniel Roseman