Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

post data from chrome extension

I have a rest method to receive data from user, here is the CURL command:

curl -X POST -H "Content-Type: application/json" -d "data_test" http://localhost:8080/datum

Now I'm trying to POST data, using java-script:

var request = new XMLHttpRequest();
let url='http://localhost:8080/datum';
let data=body;
request.open('POST', url, true);
request.setRequestHeader("Content-Type", "application/json");
request.send(data);

But this receives nothing.

I'm using this java-script in a Chrome-Extension.

like image 618
Maifee Ul Asad Avatar asked Aug 05 '26 11:08

Maifee Ul Asad


1 Answers

Here is my current code :

var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://localhost:8080/datum", true);
        xhr.setRequestHeader("Content-type", "application/json");
        xhr.onreadystatechange = function() {
          if (xhr.readyState == 4) {
            console.log(xhr.responseText);
          }
        }
        xhr.send(dat);

It works, problem was in my rest api.

like image 62
Maifee Ul Asad Avatar answered Aug 08 '26 03:08

Maifee Ul Asad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!