Error on sending POST request

Dreadnaught10

I am having trouble figuring out why my code is not working. What I am tying to do is send a POST request to an online API that will also return JSON data. after it says, "Searching for account data..." the code does not seem to execute much of anything else.

function RequestBoardInfo () {

var xmlhttp = new XMLHttpRequest();
//BoardInfoUrl = getBoardInfoUrl();
BoardInfoURL = "https://meshech.leankit.com/kanban/api/board/2847596743/searchcards";
        var parameters = {
            "searchOptions":{
                "SearchTerm": "",
                "SearchInBoard": true,
            }
        };

xmlhttp.open("POST", BoardInfoUrl, true);

xmlhttp.setRequestHeader("Content-type", "application/json");
document.getElementById("search").innerHTML = "Searching for account data...";

xmlhttp.onreadystatechange = function () {
    document.getElementById("search").innerHTML = "Processing next request...";

    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

        //define what to retrieve here
        document.getElementById("search").innerHTML = "jsonData found!";
        jsonData = xmlhttp.responseText;
        createFile();//creates a text file

        //the variable below is the parameters for the POST function in JSON.

    }
}
xmlhttp.send(JSON.stringify(parameters));

}

I know for sure that it's not entering the onreadystatechange function but i'm at a lost for why. Any help will be greatly appreciated. Thanks in advance.

EDIT: ok so I changed the code a bit to open before setrequestheader. but now it stops at open.

Andrea Casaccia

From this error:

Uncaught InvalidStateError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest':
The object's state must be OPENED.

I'd say you need to perform .open() first, and then .setRequestHeader()

https://jsfiddle.net/q6w12jae/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related